Back to index

salome-smesh  6.5.0
SMESH_Filter_i.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
00024 //  File   : SMESH_Filter_i.cxx
00025 //  Author : Alexey Petrov, OCC
00026 //  Module : SMESH
00027 //
00028 #include "SMESH_Filter_i.hxx"
00029 
00030 #include "SMESH_Gen_i.hxx"
00031 #include "SMESH_PythonDump.hxx"
00032 
00033 #include "SMDS_Mesh.hxx"
00034 #include "SMDS_MeshNode.hxx"
00035 #include "SMDS_MeshElement.hxx"
00036 #include "SMDS_ElemIterator.hxx"
00037 
00038 #include "SMESHDS_Mesh.hxx"
00039 
00040 #include <BRep_Tool.hxx>
00041 #include <Geom_CylindricalSurface.hxx>
00042 #include <Geom_Plane.hxx>
00043 #include <LDOMParser.hxx>
00044 #include <LDOMString.hxx>
00045 #include <LDOM_Document.hxx>
00046 #include <LDOM_Element.hxx>
00047 #include <LDOM_Node.hxx>
00048 #include <LDOM_XmlWriter.hxx>
00049 #include <Precision.hxx>
00050 #include <TColStd_ListIteratorOfListOfInteger.hxx>
00051 #include <TColStd_ListIteratorOfListOfReal.hxx>
00052 #include <TColStd_ListOfInteger.hxx>
00053 #include <TColStd_ListOfReal.hxx>
00054 #include <TColStd_SequenceOfHAsciiString.hxx>
00055 #include <TCollection_HAsciiString.hxx>
00056 #include <TopExp.hxx>
00057 #include <TopExp_Explorer.hxx>
00058 #include <TopoDS.hxx>
00059 #include <TopoDS_Face.hxx>
00060 #include <TopoDS_Shape.hxx>
00061 #include <TopTools_IndexedMapOfShape.hxx>
00062 
00063 using namespace SMESH;
00064 using namespace SMESH::Controls;
00065 
00066 
00067 namespace SMESH
00068 {
00069   Predicate_i*
00070   GetPredicate( Predicate_ptr thePredicate )
00071   {
00072     return DownCast<Predicate_i*>(thePredicate);
00073   }
00074 }
00075 
00076 
00077 /*
00078   Class       : BelongToGeom
00079   Description : Predicate for verifying whether entity belongs to
00080                 specified geometrical support
00081 */
00082 
00083 Controls::BelongToGeom::BelongToGeom()
00084   : myMeshDS(NULL),
00085     myType(SMDSAbs_All),
00086     myIsSubshape(false),
00087     myTolerance(Precision::Confusion())
00088 {}
00089 
00090 void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
00091 {
00092   myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
00093   init();
00094 }
00095 
00096 void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
00097 {
00098   myShape = theShape;
00099   init();
00100 }
00101 
00102 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
00103                         const TopoDS_Shape& theShape)
00104 {
00105   if (theMap.Contains(theShape)) return true;
00106 
00107   if (theShape.ShapeType() == TopAbs_COMPOUND ||
00108       theShape.ShapeType() == TopAbs_COMPSOLID)
00109   {
00110     TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
00111     for (; anIt.More(); anIt.Next())
00112     {
00113       if (!IsSubShape(theMap, anIt.Value())) {
00114         return false;
00115       }
00116     }
00117     return true;
00118   }
00119 
00120   return false;
00121 }
00122 
00123 void Controls::BelongToGeom::init()
00124 {
00125   if (!myMeshDS || myShape.IsNull()) return;
00126 
00127   // is sub-shape of main shape?
00128   TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
00129   if (aMainShape.IsNull()) {
00130     myIsSubshape = false;
00131   }
00132   else {
00133     TopTools_IndexedMapOfShape aMap;
00134     TopExp::MapShapes(aMainShape, aMap);
00135     myIsSubshape = IsSubShape(aMap, myShape);
00136   }
00137 
00138   if (!myIsSubshape)
00139   {
00140     myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
00141     myElementsOnShapePtr->SetTolerance(myTolerance);
00142     myElementsOnShapePtr->SetAllNodes(true); // belong, while false means "lays on"
00143     myElementsOnShapePtr->SetMesh(myMeshDS);
00144     myElementsOnShapePtr->SetShape(myShape, myType);
00145   }
00146 }
00147 
00148 static bool IsContains( const SMESHDS_Mesh*     theMeshDS,
00149                         const TopoDS_Shape&     theShape,
00150                         const SMDS_MeshElement* theElem,
00151                         TopAbs_ShapeEnum        theFindShapeEnum,
00152                         TopAbs_ShapeEnum        theAvoidShapeEnum = TopAbs_SHAPE )
00153 {
00154   TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
00155 
00156   while( anExp.More() )
00157   {
00158     const TopoDS_Shape& aShape = anExp.Current();
00159     if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
00160       if( aSubMesh->Contains( theElem ) )
00161         return true;
00162     }
00163     anExp.Next();
00164   }
00165   return false;
00166 }
00167 
00168 bool Controls::BelongToGeom::IsSatisfy (long theId)
00169 {
00170   if (myMeshDS == 0 || myShape.IsNull())
00171     return false;
00172 
00173   if (!myIsSubshape)
00174   {
00175     return myElementsOnShapePtr->IsSatisfy(theId);
00176   }
00177 
00178   // Case of submesh
00179   if (myType == SMDSAbs_Node)
00180   {
00181     if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
00182     {
00183       const SMDS_PositionPtr& aPosition = aNode->GetPosition();
00184       SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
00185       switch( aTypeOfPosition )
00186       {
00187       case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
00188       case SMDS_TOP_EDGE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
00189       case SMDS_TOP_FACE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
00190       case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
00191       }
00192     }
00193   }
00194   else
00195   {
00196     if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
00197     {
00198       if( myType == SMDSAbs_All )
00199       {
00200         return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
00201                IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
00202                IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
00203                IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
00204       }
00205       else if( myType == anElem->GetType() )
00206       {
00207         switch( myType )
00208         {
00209         case SMDSAbs_Edge  : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
00210         case SMDSAbs_Face  : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
00211         case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
00212                                     IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
00213         }
00214       }
00215     }
00216   }
00217 
00218   return false;
00219 }
00220 
00221 void Controls::BelongToGeom::SetType (SMDSAbs_ElementType theType)
00222 {
00223   myType = theType;
00224   init();
00225 }
00226 
00227 SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
00228 {
00229   return myType;
00230 }
00231 
00232 TopoDS_Shape Controls::BelongToGeom::GetShape()
00233 {
00234   return myShape;
00235 }
00236 
00237 const SMESHDS_Mesh* Controls::BelongToGeom::GetMeshDS() const
00238 {
00239   return myMeshDS;
00240 }
00241 
00242 void Controls::BelongToGeom::SetTolerance (double theTolerance)
00243 {
00244   myTolerance = theTolerance;
00245   if (!myIsSubshape)
00246     init();
00247 }
00248 
00249 double Controls::BelongToGeom::GetTolerance()
00250 {
00251   return myTolerance;
00252 }
00253 
00254 /*
00255   Class       : LyingOnGeom
00256   Description : Predicate for verifying whether entiy lying or partially lying on
00257                 specified geometrical support
00258 */
00259 
00260 Controls::LyingOnGeom::LyingOnGeom()
00261   : myMeshDS(NULL),
00262     myType(SMDSAbs_All),
00263     myIsSubshape(false),
00264     myTolerance(Precision::Confusion())
00265 {}
00266 
00267 void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
00268 {
00269   myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
00270   init();
00271 }
00272 
00273 void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
00274 {
00275   myShape = theShape;
00276   init();
00277 }
00278 
00279 void Controls::LyingOnGeom::init()
00280 {
00281   if (!myMeshDS || myShape.IsNull()) return;
00282 
00283   // is sub-shape of main shape?
00284   TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
00285   if (aMainShape.IsNull()) {
00286     myIsSubshape = false;
00287   }
00288   else {
00289     TopTools_IndexedMapOfShape aMap;
00290     TopExp::MapShapes(aMainShape, aMap);
00291     myIsSubshape = IsSubShape(aMap, myShape);
00292   }
00293 
00294   if (!myIsSubshape)
00295   {
00296     myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
00297     myElementsOnShapePtr->SetTolerance(myTolerance);
00298     myElementsOnShapePtr->SetAllNodes(false); // lays on, while true means "belong"
00299     myElementsOnShapePtr->SetMesh(myMeshDS);
00300     myElementsOnShapePtr->SetShape(myShape, myType);
00301   }
00302 }
00303 
00304 bool Controls::LyingOnGeom::IsSatisfy( long theId )
00305 {
00306   if ( myMeshDS == 0 || myShape.IsNull() )
00307     return false;
00308 
00309   if (!myIsSubshape)
00310   {
00311     return myElementsOnShapePtr->IsSatisfy(theId);
00312   }
00313 
00314   // Case of submesh
00315   if( myType == SMDSAbs_Node )
00316   {
00317     if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
00318     {
00319       const SMDS_PositionPtr& aPosition = aNode->GetPosition();
00320       SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
00321       switch( aTypeOfPosition )
00322       {
00323       case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
00324       case SMDS_TOP_EDGE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
00325       case SMDS_TOP_FACE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
00326       case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
00327       }
00328     }
00329   }
00330   else
00331   {
00332     if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
00333     {
00334       if( myType == SMDSAbs_All )
00335       {
00336         return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
00337                Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
00338                Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
00339                Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
00340       }
00341       else if( myType == anElem->GetType() )
00342       {
00343         switch( myType )
00344         {
00345         case SMDSAbs_Edge  : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
00346         case SMDSAbs_Face  : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
00347         case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
00348                                     Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
00349         }
00350       }
00351     }
00352   }
00353 
00354   return false;
00355 }
00356 
00357 void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
00358 {
00359   myType = theType;
00360   init();
00361 }
00362 
00363 SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
00364 {
00365   return myType;
00366 }
00367 
00368 TopoDS_Shape Controls::LyingOnGeom::GetShape()
00369 {
00370   return myShape;
00371 }
00372 
00373 const SMESHDS_Mesh* Controls::LyingOnGeom::GetMeshDS() const
00374 {
00375   return myMeshDS;
00376 }
00377 
00378 void Controls::LyingOnGeom::SetTolerance (double theTolerance)
00379 {
00380   myTolerance = theTolerance;
00381   if (!myIsSubshape)
00382     init();
00383 }
00384 
00385 double Controls::LyingOnGeom::GetTolerance()
00386 {
00387   return myTolerance;
00388 }
00389 
00390 bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh*     theMeshDS,
00391                                       const TopoDS_Shape&     theShape,
00392                                       const SMDS_MeshElement* theElem,
00393                                       TopAbs_ShapeEnum        theFindShapeEnum,
00394                                       TopAbs_ShapeEnum        theAvoidShapeEnum )
00395 {
00396   if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
00397     return true;
00398 
00399   TopTools_IndexedMapOfShape aSubShapes;
00400   TopExp::MapShapes( theShape, aSubShapes );
00401 
00402   for (int i = 1; i <= aSubShapes.Extent(); i++)
00403   {
00404     const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
00405 
00406     if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
00407       if( aSubMesh->Contains( theElem ) )
00408         return true;
00409 
00410       SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
00411       while ( aNodeIt->more() )
00412       {
00413         const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
00414         SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
00415         while ( anElemIt->more() )
00416         {
00417           const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
00418           if (anElement == theElem)
00419             return true;
00420         }
00421       }
00422     }
00423   }
00424   return false;
00425 }
00426 
00427 
00428 /*
00429                             AUXILIARY METHODS
00430 */
00431 
00432 inline
00433 const SMDS_Mesh*
00434 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
00435 {
00436   SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
00437   return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
00438 }
00439 
00440 inline
00441 SMESH::long_array*
00442 toArray( const TColStd_ListOfInteger& aList )
00443 {
00444   SMESH::long_array_var anArray = new SMESH::long_array;
00445   anArray->length( aList.Extent() );
00446   TColStd_ListIteratorOfListOfInteger anIter( aList );
00447   int i = 0;
00448   for( ; anIter.More(); anIter.Next() )
00449     anArray[ i++ ] = anIter.Value();
00450 
00451   return anArray._retn();
00452 }
00453 
00454 inline
00455 SMESH::double_array*
00456 toArray( const TColStd_ListOfReal& aList )
00457 {
00458   SMESH::double_array_var anArray = new SMESH::double_array;
00459   anArray->length( aList.Extent() );
00460   TColStd_ListIteratorOfListOfReal anIter( aList );
00461   int i = 0;
00462   for( ; anIter.More(); anIter.Next() )
00463     anArray[ i++ ] = anIter.Value();
00464 
00465   return anArray._retn();
00466 }
00467 
00468 static SMESH::Filter::Criterion createCriterion()
00469 {
00470   SMESH::Filter::Criterion aCriterion;
00471 
00472   aCriterion.Type          = FT_Undefined;
00473   aCriterion.Compare       = FT_Undefined;
00474   aCriterion.Threshold     = 0;
00475   aCriterion.UnaryOp       = FT_Undefined;
00476   aCriterion.BinaryOp      = FT_Undefined;
00477   aCriterion.ThresholdStr  = "";
00478   aCriterion.ThresholdID   = "";
00479   aCriterion.Tolerance     = Precision::Confusion();
00480   aCriterion.TypeOfElement = SMESH::ALL;
00481   aCriterion.Precision     = -1;
00482 
00483   return aCriterion;
00484 }
00485 
00486 static TopoDS_Shape getShapeByName( const char* theName )
00487 {
00488   if ( theName != 0 )
00489   {
00490     SMESH_Gen_i* aSMESHGen     = SMESH_Gen_i::GetSMESHGen();
00491     SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
00492     if ( !aStudy->_is_nil() )
00493     {
00494       SALOMEDS::Study::ListOfSObject_var aList = aStudy->FindObjectByName( theName, "GEOM" );
00495       if ( aList->length() > 0 )
00496       {
00497         CORBA::Object_var        anObj = aList[ 0 ]->GetObject();
00498         GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( anObj );
00499         return aSMESHGen->GeomObjectToShape( aGeomObj );
00500       }
00501     }
00502   }
00503   return TopoDS_Shape();
00504 }
00505 
00506 static TopoDS_Shape getShapeByID (const char* theID)
00507 {
00508   if ( theID && strlen( theID ) > 0 ) {
00509     SMESH_Gen_i*     aSMESHGen = SMESH_Gen_i::GetSMESHGen();
00510     SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
00511     if ( !aStudy->_is_nil() ) {
00512       SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
00513       if ( !aSObj->_is_nil() ) {
00514         CORBA::Object_var          obj = aSObj->GetObject();
00515         GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
00516         return aSMESHGen->GeomObjectToShape( aGeomObj );
00517       }
00518     }
00519   }
00520   return TopoDS_Shape();
00521 }
00522 
00523 static std::string getShapeNameByID (const char* theID)
00524 {
00525   if ( theID && strlen( theID ) > 0 ) {
00526     SMESH_Gen_i*     aSMESHGen = SMESH_Gen_i::GetSMESHGen();
00527     SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
00528     if ( !aStudy->_is_nil() ) {
00529       SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
00530       if ( !aSObj->_is_nil() ) {
00531         CORBA::String_var name = aSObj->GetName();
00532         return name.in();
00533       }
00534     }
00535   }
00536   return "";
00537 }
00538 
00539 /*
00540                                 FUNCTORS
00541 */
00542 
00543 /*
00544   Class       : Functor_i
00545   Description : An abstact class for all functors
00546 */
00547 Functor_i::Functor_i():
00548   SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
00549 {
00550   //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method  
00551   //PortableServer::ObjectId_var anObjectId =
00552   //  SMESH_Gen_i::GetPOA()->activate_object( this );
00553 }
00554 
00555 Functor_i::~Functor_i()
00556 {
00557   //TPythonDump()<<this<<".UnRegister()";
00558 }
00559 
00560 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
00561 {
00562   myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
00563   TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
00564 }
00565 
00566 ElementType Functor_i::GetElementType()
00567 {
00568   return ( ElementType )myFunctorPtr->GetType();
00569 }
00570 
00571 
00572 /*
00573   Class       : NumericalFunctor_i
00574   Description : Base class for numerical functors
00575 */
00576 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
00577 {
00578   return myNumericalFunctorPtr->GetValue( theId );
00579 }
00580 
00581 SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals)
00582 {
00583   std::vector<int> nbEvents;
00584   std::vector<double> funValues;
00585   std::vector<int> elements;
00586   myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements);
00587 
00588 #ifdef WIN32
00589   nbIntervals = CORBA::Short( min( nbEvents.size(), funValues.size() - 1));
00590 #else
00591   nbIntervals = CORBA::Short( std::min( nbEvents.size(), funValues.size() - 1));
00592 #endif
00593   SMESH::Histogram_var histogram = new SMESH::Histogram;
00594   if ( nbIntervals > 0 )
00595   {
00596     histogram->length( nbIntervals );
00597     for ( int i = 0; i < nbIntervals; ++i )
00598     {
00599       HistogramRectangle& rect = histogram[i];
00600       rect.nbEvents = nbEvents[i];
00601       rect.min = funValues[i];
00602       rect.max = funValues[i+1];
00603     }
00604   }
00605   return histogram._retn();
00606 }
00607 
00608 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
00609 {
00610   myNumericalFunctorPtr->SetPrecision( thePrecision );
00611   TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
00612 }
00613 
00614 CORBA::Long NumericalFunctor_i::GetPrecision()
00615 {
00616  return myNumericalFunctorPtr->GetPrecision();
00617 }
00618 
00619 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
00620 {
00621   return myNumericalFunctorPtr;
00622 }
00623 
00624 
00625 /*
00626   Class       : SMESH_MinimumAngle
00627   Description : Functor for calculation of minimum angle
00628 */
00629 MinimumAngle_i::MinimumAngle_i()
00630 {
00631   myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
00632   myFunctorPtr = myNumericalFunctorPtr;
00633 }
00634 
00635 FunctorType MinimumAngle_i::GetFunctorType()
00636 {
00637   return SMESH::FT_MinimumAngle;
00638 }
00639 
00640 
00641 /*
00642   Class       : AspectRatio
00643   Description : Functor for calculating aspect ratio
00644 */
00645 AspectRatio_i::AspectRatio_i()
00646 {
00647   myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
00648   myFunctorPtr = myNumericalFunctorPtr;
00649 }
00650 
00651 FunctorType AspectRatio_i::GetFunctorType()
00652 {
00653   return SMESH::FT_AspectRatio;
00654 }
00655 
00656 
00657 /*
00658   Class       : AspectRatio3D
00659   Description : Functor for calculating aspect ratio 3D
00660 */
00661 AspectRatio3D_i::AspectRatio3D_i()
00662 {
00663   myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
00664   myFunctorPtr = myNumericalFunctorPtr;
00665 }
00666 
00667 FunctorType AspectRatio3D_i::GetFunctorType()
00668 {
00669   return SMESH::FT_AspectRatio3D;
00670 }
00671 
00672 
00673 /*
00674   Class       : Warping_i
00675   Description : Functor for calculating warping
00676 */
00677 Warping_i::Warping_i()
00678 {
00679   myNumericalFunctorPtr.reset( new Controls::Warping() );
00680   myFunctorPtr = myNumericalFunctorPtr;
00681 }
00682 
00683 FunctorType Warping_i::GetFunctorType()
00684 {
00685   return SMESH::FT_Warping;
00686 }
00687 
00688 
00689 /*
00690   Class       : Taper_i
00691   Description : Functor for calculating taper
00692 */
00693 Taper_i::Taper_i()
00694 {
00695   myNumericalFunctorPtr.reset( new Controls::Taper() );
00696   myFunctorPtr = myNumericalFunctorPtr;
00697 }
00698 
00699 FunctorType Taper_i::GetFunctorType()
00700 {
00701   return SMESH::FT_Taper;
00702 }
00703 
00704 
00705 /*
00706   Class       : Skew_i
00707   Description : Functor for calculating skew in degrees
00708 */
00709 Skew_i::Skew_i()
00710 {
00711   myNumericalFunctorPtr.reset( new Controls::Skew() );
00712   myFunctorPtr = myNumericalFunctorPtr;
00713 }
00714 
00715 FunctorType Skew_i::GetFunctorType()
00716 {
00717   return SMESH::FT_Skew;
00718 }
00719 
00720 /*
00721   Class       : Area_i
00722   Description : Functor for calculating area
00723 */
00724 Area_i::Area_i()
00725 {
00726   myNumericalFunctorPtr.reset( new Controls::Area() );
00727   myFunctorPtr = myNumericalFunctorPtr;
00728 }
00729 
00730 FunctorType Area_i::GetFunctorType()
00731 {
00732   return SMESH::FT_Area;
00733 }
00734 
00735 /*
00736   Class       : Volume3D_i
00737   Description : Functor for calculating volume of 3D element
00738 */
00739 Volume3D_i::Volume3D_i()
00740 {
00741   myNumericalFunctorPtr.reset( new Controls::Volume() );
00742   myFunctorPtr = myNumericalFunctorPtr;
00743 }
00744 
00745 FunctorType Volume3D_i::GetFunctorType()
00746 {
00747   return SMESH::FT_Volume3D;
00748 }
00749 
00750 /*
00751   Class       : MaxElementLength2D_i
00752   Description : Functor for calculating maximum length of 2D element
00753 */
00754 MaxElementLength2D_i::MaxElementLength2D_i()
00755 {
00756   myNumericalFunctorPtr.reset( new Controls::MaxElementLength2D() );
00757   myFunctorPtr = myNumericalFunctorPtr;
00758 }
00759 
00760 FunctorType MaxElementLength2D_i::GetFunctorType()
00761 {
00762   return SMESH::FT_MaxElementLength2D;
00763 }
00764 
00765 /*
00766   Class       : MaxElementLength3D_i
00767   Description : Functor for calculating maximum length of 3D element
00768 */
00769 MaxElementLength3D_i::MaxElementLength3D_i()
00770 {
00771   myNumericalFunctorPtr.reset( new Controls::MaxElementLength3D() );
00772   myFunctorPtr = myNumericalFunctorPtr;
00773 }
00774 
00775 FunctorType MaxElementLength3D_i::GetFunctorType()
00776 {
00777   return SMESH::FT_MaxElementLength3D;
00778 }
00779 
00780 /*
00781   Class       : Length_i
00782   Description : Functor for calculating length off edge
00783 */
00784 Length_i::Length_i()
00785 {
00786   myNumericalFunctorPtr.reset( new Controls::Length() );
00787   myFunctorPtr = myNumericalFunctorPtr;
00788 }
00789 
00790 FunctorType Length_i::GetFunctorType()
00791 {
00792   return SMESH::FT_Length;
00793 }
00794 
00795 /*
00796   Class       : Length2D_i
00797   Description : Functor for calculating length of edge
00798 */
00799 Length2D_i::Length2D_i()
00800 {
00801   myNumericalFunctorPtr.reset( new Controls::Length2D() );
00802   myFunctorPtr = myNumericalFunctorPtr;
00803 }
00804 
00805 FunctorType Length2D_i::GetFunctorType()
00806 {
00807   return SMESH::FT_Length2D;
00808 }
00809 
00810 SMESH::Length2D::Values* Length2D_i::GetValues()
00811 {
00812   INFOS("Length2D_i::GetValues");
00813   SMESH::Controls::Length2D::TValues aValues;
00814   (dynamic_cast<SMESH::Controls::Length2D*>(myFunctorPtr.get()))->GetValues( aValues );
00815 
00816   long i = 0, iEnd = aValues.size();
00817 
00818   SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
00819   aResult->length(iEnd);
00820 
00821   SMESH::Controls::Length2D::TValues::const_iterator anIter;
00822   for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
00823   {
00824     const SMESH::Controls::Length2D::Value&  aVal = *anIter;
00825     SMESH::Length2D::Value &aValue = aResult[ i ];
00826 
00827     aValue.myLength = aVal.myLength;
00828     aValue.myPnt1 = aVal.myPntId[ 0 ];
00829     aValue.myPnt2 = aVal.myPntId[ 1 ];
00830   }
00831 
00832   INFOS("Length2D_i::GetValuess~");
00833   return aResult._retn();
00834 }
00835 
00836 /*
00837   Class       : MultiConnection_i
00838   Description : Functor for calculating number of faces conneted to the edge
00839 */
00840 MultiConnection_i::MultiConnection_i()
00841 {
00842   myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
00843   myFunctorPtr = myNumericalFunctorPtr;
00844 }
00845 
00846 FunctorType MultiConnection_i::GetFunctorType()
00847 {
00848   return SMESH::FT_MultiConnection;
00849 }
00850 
00851 /*
00852   Class       : MultiConnection2D_i
00853   Description : Functor for calculating number of faces conneted to the edge
00854 */
00855 MultiConnection2D_i::MultiConnection2D_i()
00856 {
00857   myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
00858   myFunctorPtr = myNumericalFunctorPtr;
00859 }
00860 
00861 FunctorType MultiConnection2D_i::GetFunctorType()
00862 {
00863   return SMESH::FT_MultiConnection2D;
00864 }
00865 
00866 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
00867 {
00868   INFOS("MultiConnection2D_i::GetValues");
00869   SMESH::Controls::MultiConnection2D::MValues aValues;
00870   (dynamic_cast<SMESH::Controls::MultiConnection2D*>(myFunctorPtr.get()))->GetValues( aValues );
00871   
00872   long i = 0, iEnd = aValues.size();
00873 
00874   SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
00875   aResult->length(iEnd);
00876 
00877   SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
00878   for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
00879   {
00880     const SMESH::Controls::MultiConnection2D::Value&  aVal = (*anIter).first;
00881     SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
00882 
00883     aValue.myPnt1 = aVal.myPntId[ 0 ];
00884     aValue.myPnt2 = aVal.myPntId[ 1 ];
00885     aValue.myNbConnects = (*anIter).second;
00886   }
00887 
00888   INFOS("Multiconnection2D_i::GetValuess~");
00889   return aResult._retn();
00890 }
00891 
00892 /*
00893                             PREDICATES
00894 */
00895 
00896 
00897 /*
00898   Class       : Predicate_i
00899   Description : Base class for all predicates
00900 */
00901 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
00902 {
00903   return myPredicatePtr->IsSatisfy( theId );
00904 }
00905 
00906 Controls::PredicatePtr Predicate_i::GetPredicate()
00907 {
00908   return myPredicatePtr;
00909 }
00910 
00911 /*
00912   Class       : BadOrientedVolume_i
00913   Description : Verify whether a mesh volume is incorrectly oriented from
00914                 the point of view of MED convention
00915 */
00916 BadOrientedVolume_i::BadOrientedVolume_i()
00917 {
00918   Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
00919   myFunctorPtr = myPredicatePtr = control;
00920 };
00921 
00922 FunctorType BadOrientedVolume_i::GetFunctorType()
00923 {
00924   return SMESH::FT_BadOrientedVolume;
00925 }
00926 
00927 /*
00928   Class       : BareBorderVolume_i
00929   Description : Verify whether a mesh volume has a free facet without a face on it
00930 */
00931 BareBorderVolume_i::BareBorderVolume_i()
00932 {
00933   Controls::PredicatePtr control( new Controls::BareBorderVolume() );
00934   myFunctorPtr = myPredicatePtr = control;
00935 };
00936 
00937 FunctorType BareBorderVolume_i::GetFunctorType()
00938 {
00939   return SMESH::FT_BareBorderVolume;
00940 }
00941 
00942 /*
00943   Class       : BareBorderFace_i
00944   Description : Verify whether a mesh face has a free border without an edge on it
00945 */
00946 BareBorderFace_i::BareBorderFace_i()
00947 {
00948   Controls::PredicatePtr control( new Controls::BareBorderFace() );
00949   myFunctorPtr = myPredicatePtr = control;
00950 };
00951 
00952 FunctorType BareBorderFace_i::GetFunctorType()
00953 {
00954   return SMESH::FT_BareBorderFace;
00955 }
00956 
00957 /*
00958   Class       : OverConstrainedVolume_i
00959   Description : Verify whether a mesh volume has only one facet shared with other volumes
00960 */
00961 OverConstrainedVolume_i::OverConstrainedVolume_i()
00962 {
00963   Controls::PredicatePtr control( new Controls::OverConstrainedVolume() );
00964   myFunctorPtr = myPredicatePtr = control;
00965 };
00966 
00967 FunctorType OverConstrainedVolume_i::GetFunctorType()
00968 {
00969   return SMESH::FT_OverConstrainedVolume;
00970 }
00971 
00972 /*
00973   Class       : OverConstrainedFace_i
00974   Description : Verify whether a mesh face has only one border shared with other faces
00975 */
00976 OverConstrainedFace_i::OverConstrainedFace_i()
00977 {
00978   Controls::PredicatePtr control( new Controls::OverConstrainedFace() );
00979   myFunctorPtr = myPredicatePtr = control;
00980 };
00981 
00982 FunctorType OverConstrainedFace_i::GetFunctorType()
00983 {
00984   return SMESH::FT_OverConstrainedFace;
00985 }
00986 
00987 /*
00988   Class       : BelongToGeom_i
00989   Description : Predicate for selection on geometrical support
00990 */
00991 BelongToGeom_i::BelongToGeom_i()
00992 {
00993   myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
00994   myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
00995   myShapeName = 0;
00996   myShapeID   = 0;
00997 }
00998 
00999 BelongToGeom_i::~BelongToGeom_i()
01000 {
01001   delete myShapeName;
01002   delete myShapeID;
01003 }
01004 
01005 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
01006 {
01007   if ( theGeom->_is_nil() )
01008     return;
01009   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
01010   GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
01011   TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
01012   myBelongToGeomPtr->SetGeom( aLocShape );
01013   TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
01014 }
01015 
01016 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
01017 {
01018   myBelongToGeomPtr->SetGeom( theShape );
01019 }
01020 
01021 void BelongToGeom_i::SetElementType(ElementType theType){
01022   myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
01023   TPythonDump()<<this<<".SetElementType("<<theType<<")";
01024 }
01025 
01026 FunctorType BelongToGeom_i::GetFunctorType()
01027 {
01028   return SMESH::FT_BelongToGeom;
01029 }
01030 
01031 void BelongToGeom_i::SetShapeName( const char* theName )
01032 {
01033   delete myShapeName;
01034   myShapeName = strdup( theName );
01035   myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
01036   TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
01037 }
01038 
01039 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
01040 {
01041   delete myShapeName;
01042   myShapeName = strdup( theName );
01043   delete myShapeID;
01044   if ( theID )
01045     myShapeID = strdup( theID );
01046   else
01047     myShapeID = 0;
01048 
01049   if ( myShapeID && myShapeName == getShapeNameByID(myShapeID))
01050     myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
01051   else
01052     myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
01053 }
01054 
01055 char* BelongToGeom_i::GetShapeName()
01056 {
01057   return CORBA::string_dup( myShapeName );
01058 }
01059 
01060 char* BelongToGeom_i::GetShapeID()
01061 {
01062   return CORBA::string_dup( myShapeID );
01063 }
01064 
01065 void BelongToGeom_i::SetTolerance( CORBA::Double theToler )
01066 {
01067   myBelongToGeomPtr->SetTolerance( theToler );
01068   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
01069 }
01070 
01071 CORBA::Double BelongToGeom_i::GetTolerance()
01072 {
01073   return myBelongToGeomPtr->GetTolerance();
01074 }
01075 
01076 /*
01077   Class       : BelongToSurface_i
01078   Description : Predicate for selection on geometrical support
01079 */
01080 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
01081 {
01082   myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
01083   myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
01084   myShapeName = 0;
01085   myShapeID   = 0;
01086   mySurfaceType = theSurfaceType;
01087 }
01088 
01089 BelongToSurface_i::~BelongToSurface_i()
01090 {
01091   delete myShapeName;
01092   delete myShapeID;
01093 }
01094 
01095 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
01096 {
01097   if ( theGeom->_is_nil() )
01098     return;
01099   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
01100   GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
01101   TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
01102 
01103   if ( aLocShape.ShapeType() == TopAbs_FACE )
01104   {
01105     Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
01106     if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
01107     {
01108       myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
01109       return;
01110     }
01111   }
01112 
01113   myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
01114 }
01115 
01116 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
01117 {
01118   delete myShapeName;
01119   myShapeName = strdup( theName );
01120   myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
01121   TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
01122 }
01123 
01124 void BelongToSurface_i::SetShape( const char* theID,  const char* theName, ElementType theType )
01125 {
01126   delete myShapeName;
01127   myShapeName = strdup( theName );
01128   delete myShapeID;
01129   if ( theID )
01130     myShapeID = strdup( theID );
01131   else
01132     myShapeID = 0;
01133   
01134   if ( myShapeID && myShapeName == getShapeNameByID(myShapeID))
01135     myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
01136   else
01137     myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
01138 }
01139 
01140 char* BelongToSurface_i::GetShapeName()
01141 {
01142   return CORBA::string_dup( myShapeName );
01143 }
01144 
01145 char* BelongToSurface_i::GetShapeID()
01146 {
01147   return CORBA::string_dup( myShapeID );
01148 }
01149 
01150 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
01151 {
01152   myElementsOnSurfacePtr->SetTolerance( theToler );
01153   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
01154 }
01155 
01156 CORBA::Double BelongToSurface_i::GetTolerance()
01157 {
01158   return myElementsOnSurfacePtr->GetTolerance();
01159 }
01160 
01161 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
01162 {
01163   myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
01164   TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
01165 }
01166 
01167 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
01168 {
01169   return myElementsOnSurfacePtr->GetUseBoundaries();
01170 }
01171 
01172 
01173 /*
01174   Class       : BelongToPlane_i
01175   Description : Verify whether mesh element lie in pointed Geom planar object
01176 */
01177 
01178 BelongToPlane_i::BelongToPlane_i()
01179 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
01180 {
01181 }
01182 
01183 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
01184 {
01185   BelongToSurface_i::SetSurface( theGeom, theType );
01186   TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
01187 }
01188 
01189 FunctorType BelongToPlane_i::GetFunctorType()
01190 {
01191   return FT_BelongToPlane;
01192 }
01193 
01194 /*
01195   Class       : BelongToCylinder_i
01196   Description : Verify whether mesh element lie in pointed Geom planar object
01197 */
01198 
01199 BelongToCylinder_i::BelongToCylinder_i()
01200 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
01201 {
01202 }
01203 
01204 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
01205 {
01206   BelongToSurface_i::SetSurface( theGeom, theType );
01207   TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
01208 }
01209 
01210 FunctorType BelongToCylinder_i::GetFunctorType()
01211 {
01212   return FT_BelongToCylinder;
01213 }
01214 
01215 /*
01216   Class       : BelongToGenSurface_i
01217   Description : Verify whether mesh element lie in pointed Geom planar object
01218 */
01219 
01220 BelongToGenSurface_i::BelongToGenSurface_i()
01221 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
01222 {
01223 }
01224 
01225 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
01226 {
01227   if ( theGeom->_is_nil() )
01228     return;
01229   TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
01230   if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
01231     aLocShape.Nullify();
01232   
01233   BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
01234   TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
01235 }
01236 
01237 FunctorType BelongToGenSurface_i::GetFunctorType()
01238 {
01239   return FT_BelongToGenSurface;
01240 }
01241 
01242 /*
01243   Class       : LyingOnGeom_i
01244   Description : Predicate for selection on geometrical support
01245 */
01246 LyingOnGeom_i::LyingOnGeom_i()
01247 {
01248   myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
01249   myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
01250   myShapeName = 0;
01251   myShapeID = 0;
01252 }
01253 
01254 LyingOnGeom_i::~LyingOnGeom_i()
01255 {
01256   delete myShapeName;
01257   delete myShapeID;
01258 }
01259 
01260 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
01261 {
01262   if ( theGeom->_is_nil() )
01263     return;
01264   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
01265   GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
01266   TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
01267   myLyingOnGeomPtr->SetGeom( aLocShape );
01268   TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
01269 }
01270 
01271 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
01272 {
01273   myLyingOnGeomPtr->SetGeom( theShape );
01274 }
01275 
01276 void LyingOnGeom_i::SetElementType(ElementType theType){
01277   myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
01278   TPythonDump()<<this<<".SetElementType("<<theType<<")";
01279 }
01280 
01281 FunctorType LyingOnGeom_i::GetFunctorType()
01282 {
01283   return SMESH::FT_LyingOnGeom;
01284 }
01285 
01286 void LyingOnGeom_i::SetShapeName( const char* theName )
01287 {
01288   delete myShapeName;
01289   myShapeName = strdup( theName );
01290   myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
01291   TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
01292 }
01293 
01294 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
01295 {
01296   delete myShapeName;
01297   myShapeName = strdup( theName );
01298   delete myShapeID;
01299   if ( theID )
01300     myShapeID = strdup( theID );
01301   else
01302     myShapeID = 0;
01303   
01304   if ( myShapeID && myShapeName == getShapeNameByID(myShapeID))
01305     myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
01306   else
01307     myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
01308 }
01309 
01310 char* LyingOnGeom_i::GetShapeName()
01311 {
01312   return CORBA::string_dup( myShapeName );
01313 }
01314 
01315 char* LyingOnGeom_i::GetShapeID()
01316 {
01317   return CORBA::string_dup( myShapeID );
01318 }
01319 
01320 void LyingOnGeom_i::SetTolerance( CORBA::Double theToler )
01321 {
01322   myLyingOnGeomPtr->SetTolerance( theToler );
01323   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
01324 }
01325 
01326 CORBA::Double LyingOnGeom_i::GetTolerance()
01327 {
01328   return myLyingOnGeomPtr->GetTolerance();
01329 }
01330 
01331 /*
01332   Class       : FreeBorders_i
01333   Description : Predicate for free borders
01334 */
01335 FreeBorders_i::FreeBorders_i()
01336 {
01337   myPredicatePtr.reset(new Controls::FreeBorders());
01338   myFunctorPtr = myPredicatePtr;
01339 }
01340 
01341 FunctorType FreeBorders_i::GetFunctorType()
01342 {
01343   return SMESH::FT_FreeBorders;
01344 }
01345 
01346 /*
01347   Class       : FreeEdges_i
01348   Description : Predicate for free borders
01349 */
01350 FreeEdges_i::FreeEdges_i()
01351 : myFreeEdgesPtr( new Controls::FreeEdges() )
01352 {
01353   myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
01354 }
01355 
01356 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
01357 {
01358   INFOS("FreeEdges_i::GetBorders");
01359   SMESH::Controls::FreeEdges::TBorders aBorders;
01360   myFreeEdgesPtr->GetBoreders( aBorders );
01361 
01362   long i = 0, iEnd = aBorders.size();
01363 
01364   SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
01365   aResult->length(iEnd);
01366 
01367   SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
01368   for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
01369   {
01370     const SMESH::Controls::FreeEdges::Border&  aBord = *anIter;
01371     SMESH::FreeEdges::Border &aBorder = aResult[ i ];
01372 
01373     aBorder.myElemId = aBord.myElemId;
01374     aBorder.myPnt1 = aBord.myPntId[ 0 ];
01375     aBorder.myPnt2 = aBord.myPntId[ 1 ];
01376   }
01377 
01378   INFOS("FreeEdges_i::GetBorders~");
01379   return aResult._retn();
01380 }
01381 
01382 FunctorType FreeEdges_i::GetFunctorType()
01383 {
01384   return SMESH::FT_FreeEdges;
01385 }
01386 
01387 /*
01388   Class       : FreeFaces_i
01389   Description : Predicate for free faces
01390 */
01391 FreeFaces_i::FreeFaces_i()
01392 {
01393   myPredicatePtr.reset(new Controls::FreeFaces());
01394   myFunctorPtr = myPredicatePtr;
01395 }
01396 
01397 FunctorType FreeFaces_i::GetFunctorType()
01398 {
01399   return SMESH::FT_FreeFaces;
01400 }
01401 
01402 /*
01403   Class       : FreeNodes_i
01404   Description : Predicate for free nodes
01405 */
01406 FreeNodes_i::FreeNodes_i()
01407 {
01408   myPredicatePtr.reset(new Controls::FreeNodes());
01409   myFunctorPtr = myPredicatePtr;
01410 }
01411 
01412 FunctorType FreeNodes_i::GetFunctorType()
01413 {
01414   return SMESH::FT_FreeNodes;
01415 }
01416 
01417 /*
01418   Class       : EqualNodes_i
01419   Description : Predicate for Equal nodes
01420 */
01421 EqualNodes_i::EqualNodes_i()
01422 {
01423   myCoincidentNodesPtr.reset(new Controls::CoincidentNodes());
01424   myFunctorPtr = myPredicatePtr = myCoincidentNodesPtr;
01425 }
01426 
01427 FunctorType EqualNodes_i::GetFunctorType()
01428 {
01429   return SMESH::FT_EqualNodes;
01430 }
01431 
01432 void EqualNodes_i::SetTolerance( double tol )
01433 {
01434   myCoincidentNodesPtr->SetTolerance( tol );
01435 }
01436 
01437 double EqualNodes_i::GetTolerance()
01438 {
01439   return myCoincidentNodesPtr->GetTolerance();
01440 }
01441 
01442 /*
01443   Class       : EqualEdges_i
01444   Description : Predicate for Equal Edges
01445 */
01446 EqualEdges_i::EqualEdges_i()
01447 {
01448   myPredicatePtr.reset(new Controls::CoincidentElements1D());
01449   myFunctorPtr = myPredicatePtr;
01450 }
01451 
01452 FunctorType EqualEdges_i::GetFunctorType()
01453 {
01454   return SMESH::FT_EqualEdges;
01455 }
01456 
01457 /*
01458   Class       : EqualFaces_i
01459   Description : Predicate for Equal Faces
01460 */
01461 EqualFaces_i::EqualFaces_i()
01462 {
01463   myPredicatePtr.reset(new Controls::CoincidentElements2D());
01464   myFunctorPtr = myPredicatePtr;
01465 }
01466 
01467 FunctorType EqualFaces_i::GetFunctorType()
01468 {
01469   return SMESH::FT_EqualFaces;
01470 }
01471 
01472 /*
01473   Class       : EqualVolumes_i
01474   Description : Predicate for Equal Volumes
01475 */
01476 EqualVolumes_i::EqualVolumes_i()
01477 {
01478   myPredicatePtr.reset(new Controls::CoincidentElements3D());
01479   myFunctorPtr = myPredicatePtr;
01480 }
01481 
01482 FunctorType EqualVolumes_i::GetFunctorType()
01483 {
01484   return SMESH::FT_EqualVolumes;
01485 }
01486 
01487 
01488 /*
01489   Class       : RangeOfIds_i
01490   Description : Predicate for Range of Ids.
01491                 Range may be specified with two ways.
01492                 1. Using AddToRange method
01493                 2. With SetRangeStr method. Parameter of this method is a string
01494                    like as "1,2,3,50-60,63,67,70-"
01495 */
01496 
01497 RangeOfIds_i::RangeOfIds_i()
01498 {
01499   myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
01500   myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
01501 }
01502 
01503 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
01504 {
01505   CORBA::Long iEnd = theIds.length();
01506   for ( CORBA::Long i = 0; i < iEnd; i++ )
01507     myRangeOfIdsPtr->AddToRange( theIds[ i ] );
01508   TPythonDump()<<this<<".SetRange("<<theIds<<")";
01509 }
01510 
01511 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
01512 {
01513   TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
01514   return myRangeOfIdsPtr->SetRangeStr(
01515     TCollection_AsciiString( (Standard_CString)theRange ) );
01516 }
01517 
01518 char* RangeOfIds_i::GetRangeStr()
01519 {
01520   TCollection_AsciiString aStr;
01521   myRangeOfIdsPtr->GetRangeStr( aStr );
01522   return CORBA::string_dup( aStr.ToCString() );
01523 }
01524 
01525 void RangeOfIds_i::SetElementType( ElementType theType )
01526 {
01527   myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
01528   TPythonDump()<<this<<".SetElementType("<<theType<<")";
01529 }
01530 
01531 FunctorType RangeOfIds_i::GetFunctorType()
01532 {
01533   return SMESH::FT_RangeOfIds;
01534 }
01535 
01536 /*
01537   Class       : LinearOrQuadratic_i
01538   Description : Predicate to verify whether a mesh element is linear
01539 */
01540 LinearOrQuadratic_i::LinearOrQuadratic_i()
01541 {
01542   myLinearOrQuadraticPtr.reset(new Controls::LinearOrQuadratic());
01543   myFunctorPtr = myPredicatePtr = myLinearOrQuadraticPtr;
01544 }
01545 
01546 void LinearOrQuadratic_i::SetElementType(ElementType theType)
01547 {
01548   myLinearOrQuadraticPtr->SetType(SMDSAbs_ElementType(theType));
01549   TPythonDump()<<this<<".SetElementType("<<theType<<")";
01550 }
01551 
01552 FunctorType LinearOrQuadratic_i::GetFunctorType()
01553 {
01554   return SMESH::FT_LinearOrQuadratic;
01555 }
01556 
01557 /*
01558   Class       : GroupColor_i
01559   Description : Functor for check color of group to whic mesh element belongs to
01560 */
01561 GroupColor_i::GroupColor_i()
01562 {
01563   myGroupColorPtr.reset(new Controls::GroupColor());
01564   myFunctorPtr = myPredicatePtr = myGroupColorPtr;
01565 }
01566 
01567 FunctorType GroupColor_i::GetFunctorType()
01568 {
01569   return SMESH::FT_GroupColor;
01570 }
01571 
01572 void GroupColor_i::SetColorStr( const char* theColor )
01573 {
01574   myGroupColorPtr->SetColorStr(
01575     TCollection_AsciiString( (Standard_CString)theColor ) );
01576   TPythonDump()<<this<<".SetColorStr('"<<theColor<<"')";
01577 }
01578 
01579 char* GroupColor_i::GetColorStr()
01580 {
01581   TCollection_AsciiString aStr;
01582   myGroupColorPtr->GetColorStr( aStr );
01583   return CORBA::string_dup( aStr.ToCString() );
01584 }
01585 
01586 void GroupColor_i::SetElementType(ElementType theType)
01587 {
01588   myGroupColorPtr->SetType(SMDSAbs_ElementType(theType));
01589   TPythonDump()<<this<<".SetElementType("<<theType<<")";
01590 }
01591 
01592 /*
01593   Class       : ElemGeomType_i
01594   Description : Predicate check is element has indicated geometry type
01595 */
01596 ElemGeomType_i::ElemGeomType_i()
01597 {
01598   myElemGeomTypePtr.reset(new Controls::ElemGeomType());
01599   myFunctorPtr = myPredicatePtr = myElemGeomTypePtr;
01600 }
01601 
01602 void ElemGeomType_i::SetElementType(ElementType theType)
01603 {
01604   myElemGeomTypePtr->SetType(SMDSAbs_ElementType(theType));
01605   TPythonDump()<<this<<".SetElementType("<<theType<<")";
01606 }
01607 
01608 void ElemGeomType_i::SetGeometryType(GeometryType theType)
01609 {
01610   myElemGeomTypePtr->SetGeomType(SMDSAbs_GeometryType(theType));
01611   TPythonDump()<<this<<".SetGeometryType("<<theType<<")";
01612 }
01613 
01614 GeometryType ElemGeomType_i::GetGeometryType() const
01615 {
01616   return (GeometryType)myElemGeomTypePtr->GetGeomType();
01617 }
01618 
01619 FunctorType ElemGeomType_i::GetFunctorType()
01620 {
01621   return SMESH::FT_ElemGeomType;
01622 }
01623 
01624 /*
01625   Class       : CoplanarFaces_i
01626   Description : Returns true if a mesh face is a coplanar neighbour to a given one
01627 */
01628 CoplanarFaces_i::CoplanarFaces_i()
01629 {
01630   myCoplanarFacesPtr.reset(new Controls::CoplanarFaces());
01631   myFunctorPtr = myPredicatePtr = myCoplanarFacesPtr;
01632 }
01633 
01634 void CoplanarFaces_i::SetFace ( CORBA::Long theFaceID )
01635 {
01636   myCoplanarFacesPtr->SetFace(theFaceID);
01637   TPythonDump()<<this<<".SetFace("<<theFaceID<<")";
01638 }
01639 
01640 void CoplanarFaces_i::SetTolerance( CORBA::Double theToler )
01641 {
01642   myCoplanarFacesPtr->SetTolerance(theToler);
01643   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
01644 }
01645 
01646 CORBA::Long CoplanarFaces_i::GetFace () const
01647 {
01648   return myCoplanarFacesPtr->GetFace();
01649 }
01650 
01651 char* CoplanarFaces_i::GetFaceAsString () const
01652 {
01653   TCollection_AsciiString str(Standard_Integer(myCoplanarFacesPtr->GetFace()));
01654   return CORBA::string_dup( str.ToCString() );
01655 }
01656 
01657 CORBA::Double CoplanarFaces_i::GetTolerance() const
01658 {
01659   return myCoplanarFacesPtr->GetTolerance();
01660 }
01661 
01662 FunctorType CoplanarFaces_i::GetFunctorType()
01663 {
01664   return SMESH::FT_CoplanarFaces;
01665 }
01666 
01667 /*
01668   Class       : Comparator_i
01669   Description : Base class for comparators
01670 */
01671 Comparator_i::Comparator_i():
01672   myNumericalFunctor( NULL )
01673 {}
01674 
01675 Comparator_i::~Comparator_i()
01676 {
01677   if ( myNumericalFunctor )
01678     myNumericalFunctor->UnRegister();
01679 }
01680 
01681 void Comparator_i::SetMargin( CORBA::Double theValue )
01682 {
01683   myComparatorPtr->SetMargin( theValue );
01684   TPythonDump()<<this<<".SetMargin("<<theValue<<")";
01685 }
01686 
01687 CORBA::Double Comparator_i::GetMargin()
01688 {
01689   return myComparatorPtr->GetMargin();
01690 }
01691 
01692 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
01693 {
01694   if ( myNumericalFunctor )
01695     myNumericalFunctor->UnRegister();
01696 
01697   myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
01698 
01699   if ( myNumericalFunctor )
01700   {
01701     myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
01702     myNumericalFunctor->Register();
01703     TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
01704   }
01705 }
01706 
01707 Controls::ComparatorPtr Comparator_i::GetComparator()
01708 {
01709   return myComparatorPtr;
01710 }
01711 
01712 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
01713 {
01714   return myNumericalFunctor;
01715 }
01716 
01717 
01718 /*
01719   Class       : LessThan_i
01720   Description : Comparator "<"
01721 */
01722 LessThan_i::LessThan_i()
01723 {
01724   myComparatorPtr.reset( new Controls::LessThan() );
01725   myFunctorPtr = myPredicatePtr = myComparatorPtr;
01726 }
01727 
01728 FunctorType LessThan_i::GetFunctorType()
01729 {
01730   return SMESH::FT_LessThan;
01731 }
01732 
01733 
01734 /*
01735   Class       : MoreThan_i
01736   Description : Comparator ">"
01737 */
01738 MoreThan_i::MoreThan_i()
01739 {
01740   myComparatorPtr.reset( new Controls::MoreThan() );
01741   myFunctorPtr = myPredicatePtr = myComparatorPtr;
01742 }
01743 
01744 FunctorType MoreThan_i::GetFunctorType()
01745 {
01746   return SMESH::FT_MoreThan;
01747 }
01748 
01749 
01750 /*
01751   Class       : EqualTo_i
01752   Description : Comparator "="
01753 */
01754 EqualTo_i::EqualTo_i()
01755 : myEqualToPtr( new Controls::EqualTo() )
01756 {
01757   myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
01758 }
01759 
01760 void EqualTo_i::SetTolerance( CORBA::Double theToler )
01761 {
01762   myEqualToPtr->SetTolerance( theToler );
01763   TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
01764 }
01765 
01766 CORBA::Double EqualTo_i::GetTolerance()
01767 {
01768   return myEqualToPtr->GetTolerance();
01769 }
01770 
01771 FunctorType EqualTo_i::GetFunctorType()
01772 {
01773   return SMESH::FT_EqualTo;
01774 }
01775 
01776 /*
01777   Class       : LogicalNOT_i
01778   Description : Logical NOT predicate
01779 */
01780 LogicalNOT_i::LogicalNOT_i()
01781 : myPredicate( NULL ),
01782   myLogicalNOTPtr( new Controls::LogicalNOT() )
01783 {
01784   myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
01785 }
01786 
01787 LogicalNOT_i::~LogicalNOT_i()
01788 {
01789   if ( myPredicate )
01790     myPredicate->UnRegister();
01791 }
01792 
01793 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
01794 {
01795   if ( myPredicate )
01796     myPredicate->UnRegister();
01797 
01798   myPredicate = SMESH::GetPredicate(thePredicate);
01799 
01800   if ( myPredicate ){
01801     myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
01802     myPredicate->Register();
01803     TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
01804   }
01805 }
01806 
01807 FunctorType LogicalNOT_i::GetFunctorType()
01808 {
01809   return SMESH::FT_LogicalNOT;
01810 }
01811 
01812 Predicate_i* LogicalNOT_i::GetPredicate_i()
01813 {
01814   return myPredicate;
01815 }
01816 
01817 
01818 /*
01819   Class       : LogicalBinary_i
01820   Description : Base class for binary logical predicate
01821 */
01822 LogicalBinary_i::LogicalBinary_i()
01823 : myPredicate1( NULL ),
01824   myPredicate2( NULL )
01825 {}
01826 
01827 LogicalBinary_i::~LogicalBinary_i()
01828 {
01829   if ( myPredicate1 )
01830     myPredicate1->UnRegister();
01831 
01832   if ( myPredicate2 )
01833     myPredicate2->UnRegister();
01834 }
01835 
01836 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
01837 {
01838   if ( myPredicate1 )
01839     myPredicate1->SetMesh( theMesh );
01840 
01841   if ( myPredicate2 )
01842     myPredicate2->SetMesh( theMesh );
01843 }
01844 
01845 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
01846 {
01847   if ( myPredicate1 )
01848     myPredicate1->UnRegister();
01849 
01850   myPredicate1 = SMESH::GetPredicate(thePredicate);
01851 
01852   if ( myPredicate1 ){
01853     myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
01854     myPredicate1->Register();
01855     TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
01856   }
01857 }
01858 
01859 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
01860 {
01861   if ( myPredicate2 )
01862     myPredicate2->UnRegister();
01863 
01864   myPredicate2 = SMESH::GetPredicate(thePredicate);
01865 
01866   if ( myPredicate2 ){
01867     myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
01868     myPredicate2->Register();
01869     TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
01870   }
01871 }
01872 
01873 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
01874 {
01875   return myLogicalBinaryPtr;
01876 }
01877 
01878 Predicate_i* LogicalBinary_i::GetPredicate1_i()
01879 {
01880   return myPredicate1;
01881 }
01882 Predicate_i* LogicalBinary_i::GetPredicate2_i()
01883 {
01884   return myPredicate2;
01885 }
01886 
01887 
01888 /*
01889   Class       : LogicalAND_i
01890   Description : Logical AND
01891 */
01892 LogicalAND_i::LogicalAND_i()
01893 {
01894   myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
01895   myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
01896 }
01897 
01898 FunctorType LogicalAND_i::GetFunctorType()
01899 {
01900   return SMESH::FT_LogicalAND;
01901 }
01902 
01903 
01904 /*
01905   Class       : LogicalOR_i
01906   Description : Logical OR
01907 */
01908 LogicalOR_i::LogicalOR_i()
01909 {
01910   myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
01911   myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
01912 }
01913 
01914 FunctorType LogicalOR_i::GetFunctorType()
01915 {
01916   return SMESH::FT_LogicalOR;
01917 }
01918 
01919 
01920 /*
01921                             FILTER MANAGER
01922 */
01923 
01924 FilterManager_i::FilterManager_i()
01925 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
01926 {
01927   //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
01928   //PortableServer::ObjectId_var anObjectId =
01929   //  SMESH_Gen_i::GetPOA()->activate_object( this );
01930 }
01931 
01932 
01933 FilterManager_i::~FilterManager_i()
01934 {
01935   //TPythonDump()<<this<<".UnRegister()";
01936 }
01937 
01938 
01939 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
01940 {
01941   SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
01942   SMESH::MinimumAngle_var anObj = aServant->_this();
01943   TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
01944   return anObj._retn();
01945 }
01946 
01947 
01948 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
01949 {
01950   SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
01951   SMESH::AspectRatio_var anObj = aServant->_this();
01952   TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
01953   return anObj._retn();
01954 }
01955 
01956 
01957 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
01958 {
01959   SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
01960   SMESH::AspectRatio3D_var anObj = aServant->_this();
01961   TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
01962   return anObj._retn();
01963 }
01964 
01965 
01966 Warping_ptr FilterManager_i::CreateWarping()
01967 {
01968   SMESH::Warping_i* aServant = new SMESH::Warping_i();
01969   SMESH::Warping_var anObj = aServant->_this();
01970   TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
01971   return anObj._retn();
01972 }
01973 
01974 
01975 Taper_ptr FilterManager_i::CreateTaper()
01976 {
01977   SMESH::Taper_i* aServant = new SMESH::Taper_i();
01978   SMESH::Taper_var anObj = aServant->_this();
01979   TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
01980   return anObj._retn();
01981 }
01982 
01983 
01984 Skew_ptr FilterManager_i::CreateSkew()
01985 {
01986   SMESH::Skew_i* aServant = new SMESH::Skew_i();
01987   SMESH::Skew_var anObj = aServant->_this();
01988   TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
01989   return anObj._retn();
01990 }
01991 
01992 
01993 Area_ptr FilterManager_i::CreateArea()
01994 {
01995   SMESH::Area_i* aServant = new SMESH::Area_i();
01996   SMESH::Area_var anObj = aServant->_this();
01997   TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
01998   return anObj._retn();
01999 }
02000 
02001 
02002 Volume3D_ptr FilterManager_i::CreateVolume3D()
02003 {
02004   SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
02005   SMESH::Volume3D_var anObj = aServant->_this();
02006   TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
02007   return anObj._retn();
02008 }
02009 
02010 
02011 MaxElementLength2D_ptr FilterManager_i::CreateMaxElementLength2D()
02012 {
02013   SMESH::MaxElementLength2D_i* aServant = new SMESH::MaxElementLength2D_i();
02014   SMESH::MaxElementLength2D_var anObj = aServant->_this();
02015   TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength2D()";
02016   return anObj._retn();
02017 }
02018 
02019 
02020 MaxElementLength3D_ptr FilterManager_i::CreateMaxElementLength3D()
02021 {
02022   SMESH::MaxElementLength3D_i* aServant = new SMESH::MaxElementLength3D_i();
02023   SMESH::MaxElementLength3D_var anObj = aServant->_this();
02024   TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength3D()";
02025   return anObj._retn();
02026 }
02027 
02028 
02029 Length_ptr FilterManager_i::CreateLength()
02030 {
02031   SMESH::Length_i* aServant = new SMESH::Length_i();
02032   SMESH::Length_var anObj = aServant->_this();
02033   TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
02034   return anObj._retn();
02035 }
02036 
02037 Length2D_ptr FilterManager_i::CreateLength2D()
02038 {
02039   SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
02040   SMESH::Length2D_var anObj = aServant->_this();
02041   TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
02042   return anObj._retn();
02043 }
02044 
02045 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
02046 {
02047   SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
02048   SMESH::MultiConnection_var anObj = aServant->_this();
02049   TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
02050   return anObj._retn();
02051 }
02052 
02053 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
02054 {
02055   SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
02056   SMESH::MultiConnection2D_var anObj = aServant->_this();
02057   TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
02058   return anObj._retn();
02059 }
02060 
02061 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
02062 {
02063   SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
02064   SMESH::BelongToGeom_var anObj = aServant->_this();
02065   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
02066   return anObj._retn();
02067 }
02068 
02069 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
02070 {
02071   SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
02072   SMESH::BelongToPlane_var anObj = aServant->_this();
02073   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
02074   return anObj._retn();
02075 }
02076 
02077 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
02078 {
02079   SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
02080   SMESH::BelongToCylinder_var anObj = aServant->_this();
02081   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
02082   return anObj._retn();
02083 }
02084 
02085 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
02086 {
02087   SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
02088   SMESH::BelongToGenSurface_var anObj = aServant->_this();
02089   TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
02090   return anObj._retn();
02091 }
02092 
02093 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
02094 {
02095   SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
02096   SMESH::LyingOnGeom_var anObj = aServant->_this();
02097   TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
02098   return anObj._retn();
02099 }
02100 
02101 CoplanarFaces_ptr FilterManager_i::CreateCoplanarFaces()
02102 {
02103   SMESH::CoplanarFaces_i* aServant = new SMESH::CoplanarFaces_i();
02104   SMESH::CoplanarFaces_var anObj = aServant->_this();
02105   TPythonDump()<<aServant<<" = "<<this<<".CreateCoplanarFaces()";
02106   return anObj._retn();
02107 }
02108 
02109 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
02110 {
02111   SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
02112   SMESH::FreeBorders_var anObj = aServant->_this();
02113   TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
02114   return anObj._retn();
02115 }
02116 
02117 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
02118 {
02119   SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
02120   SMESH::FreeEdges_var anObj = aServant->_this();
02121   TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
02122   return anObj._retn();
02123 }
02124 
02125 FreeFaces_ptr FilterManager_i::CreateFreeFaces()
02126 {
02127   SMESH::FreeFaces_i* aServant = new SMESH::FreeFaces_i();
02128   SMESH::FreeFaces_var anObj = aServant->_this();
02129   TPythonDump()<<aServant<<" = "<<this<<".CreateFreeFaces()";
02130   return anObj._retn();
02131 }
02132 
02133 FreeNodes_ptr FilterManager_i::CreateFreeNodes()
02134 {
02135   SMESH::FreeNodes_i* aServant = new SMESH::FreeNodes_i();
02136   SMESH::FreeNodes_var anObj = aServant->_this();
02137   TPythonDump()<<aServant<<" = "<<this<<".CreateFreeNodes()";
02138   return anObj._retn();
02139 }
02140 
02141 EqualNodes_ptr FilterManager_i::CreateEqualNodes()
02142 {
02143   SMESH::EqualNodes_i* aServant = new SMESH::EqualNodes_i();
02144   SMESH::EqualNodes_var anObj = aServant->_this();
02145   TPythonDump()<<aServant<<" = "<<this<<".CreateEqualNodes()";
02146   return anObj._retn();
02147 }
02148 
02149 EqualEdges_ptr FilterManager_i::CreateEqualEdges()
02150 {
02151   SMESH::EqualEdges_i* aServant = new SMESH::EqualEdges_i();
02152   SMESH::EqualEdges_var anObj = aServant->_this();
02153   TPythonDump()<<aServant<<" = "<<this<<".CreateEqualEdges()";
02154   return anObj._retn();
02155 }
02156 EqualFaces_ptr FilterManager_i::CreateEqualFaces()
02157 {
02158   SMESH::EqualFaces_i* aServant = new SMESH::EqualFaces_i();
02159   SMESH::EqualFaces_var anObj = aServant->_this();
02160   TPythonDump()<<aServant<<" = "<<this<<".CreateEqualFaces()";
02161   return anObj._retn();
02162 }
02163 EqualVolumes_ptr FilterManager_i::CreateEqualVolumes()
02164 {
02165   SMESH::EqualVolumes_i* aServant = new SMESH::EqualVolumes_i();
02166   SMESH::EqualVolumes_var anObj = aServant->_this();
02167   TPythonDump()<<aServant<<" = "<<this<<".CreateEqualVolumes()";
02168   return anObj._retn();
02169 }
02170 
02171 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
02172 {
02173   SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
02174   SMESH::RangeOfIds_var anObj = aServant->_this();
02175   TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
02176   return anObj._retn();
02177 }
02178 
02179 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
02180 {
02181   SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
02182   SMESH::BadOrientedVolume_var anObj = aServant->_this();
02183   TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
02184   return anObj._retn();
02185 }
02186 
02187 BareBorderVolume_ptr FilterManager_i::CreateBareBorderVolume()
02188 {
02189   SMESH::BareBorderVolume_i* aServant = new SMESH::BareBorderVolume_i();
02190   SMESH::BareBorderVolume_var anObj = aServant->_this();
02191   TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderVolume()";
02192   return anObj._retn();
02193 }
02194 
02195 BareBorderFace_ptr FilterManager_i::CreateBareBorderFace()
02196 {
02197   SMESH::BareBorderFace_i* aServant = new SMESH::BareBorderFace_i();
02198   SMESH::BareBorderFace_var anObj = aServant->_this();
02199   TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderFace()";
02200   return anObj._retn();
02201 }
02202 
02203 OverConstrainedVolume_ptr FilterManager_i::CreateOverConstrainedVolume()
02204 {
02205   SMESH::OverConstrainedVolume_i* aServant = new SMESH::OverConstrainedVolume_i();
02206   SMESH::OverConstrainedVolume_var anObj = aServant->_this();
02207   TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedVolume()";
02208   return anObj._retn();
02209 }
02210 
02211 OverConstrainedFace_ptr FilterManager_i::CreateOverConstrainedFace()
02212 {
02213   SMESH::OverConstrainedFace_i* aServant = new SMESH::OverConstrainedFace_i();
02214   SMESH::OverConstrainedFace_var anObj = aServant->_this();
02215   TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedFace()";
02216   return anObj._retn();
02217 }
02218 
02219 LessThan_ptr FilterManager_i::CreateLessThan()
02220 {
02221   SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
02222   SMESH::LessThan_var anObj = aServant->_this();
02223   TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
02224   return anObj._retn();
02225 }
02226 
02227 MoreThan_ptr FilterManager_i::CreateMoreThan()
02228 {
02229   SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
02230   SMESH::MoreThan_var anObj = aServant->_this();
02231   TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
02232   return anObj._retn();
02233 }
02234 
02235 EqualTo_ptr FilterManager_i::CreateEqualTo()
02236 {
02237   SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
02238   SMESH::EqualTo_var anObj = aServant->_this();
02239   TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
02240   return anObj._retn();
02241 }
02242 
02243 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
02244 {
02245   SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
02246   SMESH::LogicalNOT_var anObj = aServant->_this();
02247   TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
02248   return anObj._retn();
02249 }
02250 
02251 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
02252 {
02253   SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
02254   SMESH::LogicalAND_var anObj = aServant->_this();
02255   TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
02256   return anObj._retn();
02257 }
02258 
02259 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
02260 {
02261   SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
02262   SMESH::LogicalOR_var anObj = aServant->_this();
02263   TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
02264   return anObj._retn();
02265 }
02266 
02267 LinearOrQuadratic_ptr FilterManager_i::CreateLinearOrQuadratic()
02268 {
02269   SMESH::LinearOrQuadratic_i* aServant = new SMESH::LinearOrQuadratic_i();
02270   SMESH::LinearOrQuadratic_var anObj = aServant->_this();
02271   TPythonDump()<<aServant<<" = "<<this<<".CreateLinearOrQuadratic()";
02272   return anObj._retn();
02273 }
02274 
02275 GroupColor_ptr FilterManager_i::CreateGroupColor()
02276 {
02277   SMESH::GroupColor_i* aServant = new SMESH::GroupColor_i();
02278   SMESH::GroupColor_var anObj = aServant->_this();
02279   TPythonDump()<<aServant<<" = "<<this<<".CreateGroupColor()";
02280   return anObj._retn();
02281 }
02282 
02283 ElemGeomType_ptr FilterManager_i::CreateElemGeomType()
02284 {
02285   SMESH::ElemGeomType_i* aServant = new SMESH::ElemGeomType_i();
02286   SMESH::ElemGeomType_var anObj = aServant->_this();
02287   TPythonDump()<<aServant<<" = "<<this<<".CreateElemGeomType()";
02288   return anObj._retn();
02289 }
02290 
02291 Filter_ptr FilterManager_i::CreateFilter()
02292 {
02293   SMESH::Filter_i* aServant = new SMESH::Filter_i();
02294   SMESH::Filter_var anObj = aServant->_this();
02295   TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
02296   return anObj._retn();
02297 }
02298 
02299 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
02300 {
02301   SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
02302   SMESH::FilterLibrary_var anObj = aServant->_this();
02303   TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary('"<<aFileName<<"')";
02304   return anObj._retn();
02305 }
02306 
02307 FilterLibrary_ptr FilterManager_i::CreateLibrary()
02308 {
02309   SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
02310   SMESH::FilterLibrary_var anObj = aServant->_this();
02311   TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
02312   return anObj._retn();
02313 }
02314 
02315 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
02316 {
02317   TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
02318   return remove( aFileName ) ? false : true;
02319 }
02320 
02321 //=============================================================================
02327 //=============================================================================
02328 
02329 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
02330 {
02331   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
02332   SMESH::FilterManager_var anObj = aFilter->_this();
02333   return anObj._retn();
02334 }
02335 
02336 
02337 /*
02338                               FILTER
02339 */
02340 
02341 //=======================================================================
02342 // name    : Filter_i::Filter_i
02343 // Purpose : Constructor
02344 //=======================================================================
02345 Filter_i::Filter_i()
02346 : myPredicate( NULL )
02347 {}
02348 
02349 //=======================================================================
02350 // name    : Filter_i::~Filter_i
02351 // Purpose : Destructor
02352 //=======================================================================
02353 Filter_i::~Filter_i()
02354 {
02355   if ( myPredicate )
02356     myPredicate->UnRegister();
02357 
02358   if(!CORBA::is_nil(myMesh))
02359     myMesh->UnRegister();
02360 
02361   //TPythonDump()<<this<<".UnRegister()";
02362 }
02363 
02364 //=======================================================================
02365 // name    : Filter_i::SetPredicate
02366 // Purpose : Set predicate
02367 //=======================================================================
02368 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
02369 {
02370   if ( myPredicate )
02371     myPredicate->UnRegister();
02372 
02373   myPredicate = SMESH::GetPredicate(thePredicate);
02374 
02375   if ( myPredicate )
02376   {
02377     myFilter.SetPredicate( myPredicate->GetPredicate() );
02378     myPredicate->Register();
02379     if ( const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh))
02380       myPredicate->GetPredicate()->SetMesh( aMesh );
02381     TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
02382   }
02383   std::list<TPredicateChangeWaiter*>::iterator i = myWaiters.begin();
02384   for ( ; i != myWaiters.end(); ++i )
02385     (*i)->PredicateChanged();
02386 }
02387 
02388 //=======================================================================
02389 // name    : Filter_i::GetElementType
02390 // Purpose : Get entity type
02391 //=======================================================================
02392 SMESH::ElementType Filter_i::GetElementType()
02393 {
02394   return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
02395 }
02396 
02397 //=======================================================================
02398 // name    : Filter_i::SetMesh
02399 // Purpose : Set mesh
02400 //=======================================================================
02401 void
02402 Filter_i::
02403 SetMesh( SMESH_Mesh_ptr theMesh )
02404 {
02405   if(!CORBA::is_nil(theMesh))
02406     theMesh->Register();
02407 
02408   if(!CORBA::is_nil(myMesh))
02409     myMesh->UnRegister();
02410 
02411   myMesh = SMESH_Mesh::_duplicate( theMesh );
02412   TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
02413 
02414   if ( myPredicate )
02415     if ( const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
02416       myPredicate->GetPredicate()->SetMesh( aMesh );
02417 }
02418 
02419 SMESH::long_array*
02420 Filter_i::
02421 GetIDs()
02422 {
02423   return GetElementsId(myMesh);
02424 }
02425 
02426 //=======================================================================
02427 // name    : Filter_i::GetElementsId
02428 // Purpose : Get ids of entities
02429 //=======================================================================
02430 void
02431 Filter_i::
02432 GetElementsId( Predicate_i* thePredicate,
02433                const SMDS_Mesh* theMesh,
02434                Controls::Filter::TIdSequence& theSequence )
02435 {
02436   if (thePredicate)
02437     Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
02438 }
02439 
02440 void
02441 Filter_i::
02442 GetElementsId( Predicate_i* thePredicate,
02443                SMESH_Mesh_ptr theMesh,
02444                Controls::Filter::TIdSequence& theSequence )
02445 {
02446   if (thePredicate) 
02447     if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
02448       Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
02449 }
02450 
02451 SMESH::long_array*
02452 Filter_i::
02453 GetElementsId( SMESH_Mesh_ptr theMesh )
02454 {
02455   SMESH::long_array_var anArray = new SMESH::long_array;
02456   if(!CORBA::is_nil(theMesh) && myPredicate){
02457     Controls::Filter::TIdSequence aSequence;
02458     GetElementsId(myPredicate,theMesh,aSequence);
02459     long i = 0, iEnd = aSequence.size();
02460     anArray->length( iEnd );
02461     for ( ; i < iEnd; i++ )
02462       anArray[ i ] = aSequence[i];
02463   }
02464   return anArray._retn();
02465 }
02466 
02467 template<class TElement, class TIterator, class TPredicate>
02468 static void collectMeshInfo(const TIterator& theItr,
02469                             TPredicate& thePred,
02470                             SMESH::long_array& theRes)
02471 {         
02472   if (!theItr)
02473     return;
02474   while (theItr->more()) {
02475     const SMDS_MeshElement* anElem = theItr->next();
02476     if ( thePred->IsSatisfy( anElem->GetID() ) )
02477       theRes[ anElem->GetEntityType() ]++;
02478   }
02479 }
02480 
02481 //=============================================================================
02485 //=============================================================================
02486 SMESH::long_array* ::Filter_i::GetMeshInfo()
02487 {
02488   SMESH::long_array_var aRes = new SMESH::long_array();
02489   aRes->length(SMESH::Entity_Last);
02490   for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
02491     aRes[i] = 0;
02492 
02493   if(!CORBA::is_nil(myMesh) && myPredicate) {
02494     const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
02495     SMDS_ElemIteratorPtr it;
02496     switch( GetElementType() )
02497     {
02498     case SMDSAbs_Node:
02499       collectMeshInfo<const SMDS_MeshNode*>(aMesh->nodesIterator(),myPredicate,aRes);
02500       break;
02501     case SMDSAbs_Edge:
02502       collectMeshInfo<const SMDS_MeshElement*>(aMesh->edgesIterator(),myPredicate,aRes);
02503       break;
02504     case SMDSAbs_Face:
02505       collectMeshInfo<const SMDS_MeshElement*>(aMesh->facesIterator(),myPredicate,aRes);
02506       break;
02507     case SMDSAbs_Volume:
02508       collectMeshInfo<const SMDS_MeshElement*>(aMesh->volumesIterator(),myPredicate,aRes);
02509       break;
02510     case SMDSAbs_All:
02511     default:
02512       collectMeshInfo<const SMDS_MeshElement*>(aMesh->elementsIterator(),myPredicate,aRes);
02513       break;
02514     }
02515   }
02516 
02517   return aRes._retn();  
02518 }
02519 
02520 //================================================================================
02525 //================================================================================
02526 
02527 SMESH::array_of_ElementType* Filter_i::GetTypes()
02528 {
02529   SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
02530 
02531   // check if any element passes through the filter
02532   if ( !CORBA::is_nil(myMesh) && myPredicate )
02533   {
02534     const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
02535     SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
02536     bool satisfies = false;
02537     while ( !satisfies && it->more() )
02538       satisfies = myPredicate->IsSatisfy( it->next()->GetID() );
02539     if ( satisfies ) {
02540       types->length( 1 );
02541       types[0] = GetElementType();
02542     }
02543   }
02544   return types._retn();
02545 }
02546 
02547 //=======================================================================
02548 //function : GetMesh
02549 //purpose  : Returns mesh
02550 //=======================================================================
02551 
02552 SMESH::SMESH_Mesh_ptr Filter_i::GetMesh()
02553 {
02554   return SMESH_Mesh::_duplicate( myMesh );
02555 }
02556 
02557 //================================================================================
02561 //================================================================================
02562 
02563 void Filter_i::AddWaiter( TPredicateChangeWaiter* waiter )
02564 {
02565   if ( waiter )
02566     myWaiters.push_back( waiter );
02567 }
02568 
02569 //================================================================================
02573 //================================================================================
02574 
02575 void Filter_i::RemoveWaiter( TPredicateChangeWaiter* waiter )
02576 {
02577   myWaiters.remove( waiter );
02578 }
02579 
02580 //=======================================================================
02581 // name    : getCriteria
02582 // Purpose : Retrieve criterions from predicate
02583 //=======================================================================
02584 static inline bool getCriteria( Predicate_i*                thePred,
02585                                 SMESH::Filter::Criteria_out theCriteria )
02586 {
02587   int aFType = thePred->GetFunctorType();
02588 
02589   switch ( aFType )
02590   {
02591   case FT_FreeBorders:
02592   case FT_FreeEdges:
02593   case FT_FreeFaces:
02594   case FT_LinearOrQuadratic:
02595   case FT_FreeNodes:
02596   case FT_EqualEdges:
02597   case FT_EqualFaces:
02598   case FT_EqualVolumes:
02599   case FT_BadOrientedVolume:
02600   case FT_BareBorderVolume:
02601   case FT_BareBorderFace:
02602   case FT_OverConstrainedVolume:
02603   case FT_OverConstrainedFace:
02604     {
02605       CORBA::ULong i = theCriteria->length();
02606       theCriteria->length( i + 1 );
02607 
02608       theCriteria[ i ] = createCriterion();
02609 
02610       theCriteria[ i ].Type = aFType;
02611       theCriteria[ i ].TypeOfElement = thePred->GetElementType();
02612       return true;
02613     }
02614   case FT_BelongToGeom:
02615     {
02616       BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
02617 
02618       CORBA::ULong i = theCriteria->length();
02619       theCriteria->length( i + 1 );
02620 
02621       theCriteria[ i ] = createCriterion();
02622 
02623       theCriteria[ i ].Type          = FT_BelongToGeom;
02624       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
02625       theCriteria[ i ].ThresholdID   = aPred->GetShapeID();
02626       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
02627       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
02628 
02629       return true;
02630     }
02631   case FT_BelongToPlane:
02632   case FT_BelongToCylinder:
02633   case FT_BelongToGenSurface:
02634     {
02635       BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
02636 
02637       CORBA::ULong i = theCriteria->length();
02638       theCriteria->length( i + 1 );
02639 
02640       theCriteria[ i ] = createCriterion();
02641 
02642       theCriteria[ i ].Type          = aFType;
02643       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
02644       theCriteria[ i ].ThresholdID   = aPred->GetShapeID();
02645       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
02646       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
02647 
02648       return true;
02649     }
02650    case FT_LyingOnGeom:
02651     {
02652       LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
02653 
02654       CORBA::ULong i = theCriteria->length();
02655       theCriteria->length( i + 1 );
02656 
02657       theCriteria[ i ] = createCriterion();
02658 
02659       theCriteria[ i ].Type          = FT_LyingOnGeom;
02660       theCriteria[ i ].ThresholdStr  = aPred->GetShapeName();
02661       theCriteria[ i ].ThresholdID   = aPred->GetShapeID();
02662       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
02663       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
02664 
02665       return true;
02666     }
02667    case FT_CoplanarFaces:
02668     {
02669       CoplanarFaces_i* aPred = dynamic_cast<CoplanarFaces_i*>( thePred );
02670 
02671       CORBA::ULong i = theCriteria->length();
02672       theCriteria->length( i + 1 );
02673 
02674       theCriteria[ i ] = createCriterion();
02675       CORBA::String_var faceId = aPred->GetFaceAsString();
02676 
02677       theCriteria[ i ].Type          = FT_CoplanarFaces;
02678       theCriteria[ i ].ThresholdID   = faceId;
02679       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
02680 
02681       return true;
02682     }
02683   case FT_EqualNodes:
02684     {
02685       EqualNodes_i* aPred = dynamic_cast<EqualNodes_i*>( thePred );
02686 
02687       CORBA::ULong i = theCriteria->length();
02688       theCriteria->length( i + 1 );
02689 
02690       theCriteria[ i ] = createCriterion();
02691 
02692       theCriteria[ i ].Type          = FT_EqualNodes;
02693       theCriteria[ i ].Tolerance     = aPred->GetTolerance();
02694 
02695       return true;
02696     }
02697   case FT_RangeOfIds:
02698     {
02699       RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
02700 
02701       CORBA::ULong i = theCriteria->length();
02702       theCriteria->length( i + 1 );
02703 
02704       theCriteria[ i ] = createCriterion();
02705 
02706       theCriteria[ i ].Type          = FT_RangeOfIds;
02707       theCriteria[ i ].ThresholdStr  = aPred->GetRangeStr();
02708       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
02709 
02710       return true;
02711     }
02712   case FT_LessThan:
02713   case FT_MoreThan:
02714   case FT_EqualTo:
02715     {
02716       Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
02717 
02718       CORBA::ULong i = theCriteria->length();
02719       theCriteria->length( i + 1 );
02720 
02721       theCriteria[ i ] = createCriterion();
02722 
02723       theCriteria[ i ].Type      = aCompar->GetNumFunctor_i()->GetFunctorType();
02724       theCriteria[ i ].Compare   = aFType;
02725       theCriteria[ i ].Threshold = aCompar->GetMargin();
02726       theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
02727 
02728       if ( aFType == FT_EqualTo )
02729       {
02730         EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
02731         theCriteria[ i ].Tolerance = aCompar->GetTolerance();
02732       }
02733     }
02734     return true;
02735 
02736   case FT_LogicalNOT:
02737     {
02738       Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
02739       getCriteria( aPred, theCriteria );
02740       theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
02741     }
02742     return true;
02743 
02744   case FT_LogicalAND:
02745   case FT_LogicalOR:
02746     {
02747       Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
02748       Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
02749       if ( !getCriteria( aPred1, theCriteria ) )
02750         return false;
02751       theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
02752       return getCriteria( aPred2, theCriteria );
02753     }
02754   case FT_GroupColor:
02755     {
02756       CORBA::ULong i = theCriteria->length();
02757       theCriteria->length( i + 1 );
02758 
02759       theCriteria[ i ] = createCriterion();
02760 
02761       GroupColor_i* aPred = dynamic_cast<GroupColor_i*>( thePred );
02762       theCriteria[ i ].Type          = aFType;
02763       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
02764       theCriteria[ i ].ThresholdStr  = aPred->GetColorStr();
02765 
02766       return true;
02767     }
02768   case FT_ElemGeomType:
02769     {
02770       CORBA::ULong i = theCriteria->length();
02771       theCriteria->length( i + 1 );
02772 
02773       theCriteria[ i ] = createCriterion();
02774 
02775       ElemGeomType_i* aPred = dynamic_cast<ElemGeomType_i*>( thePred );
02776       theCriteria[ i ].Type          = aFType;
02777       theCriteria[ i ].TypeOfElement = aPred->GetElementType();
02778       theCriteria[ i ].Threshold     = (double)aPred->GetGeometryType();
02779       return true;
02780     }
02781 
02782   case FT_Undefined:
02783     return false;
02784   default:
02785     return false;
02786   }
02787 }
02788 
02789 //=======================================================================
02790 // name    : Filter_i::GetCriteria
02791 // Purpose : Retrieve criterions from predicate
02792 //=======================================================================
02793 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
02794 {
02795   theCriteria = new SMESH::Filter::Criteria;
02796   return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
02797 }
02798 
02799 //=======================================================================
02800 // name    : Filter_i::SetCriteria
02801 // Purpose : Create new predicate and set criterions in it
02802 //=======================================================================
02803 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
02804 {
02805   if ( myPredicate != 0 )
02806     myPredicate->UnRegister();
02807 
02808   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
02809   FilterManager_ptr aFilterMgr = aFilter->_this();
02810 
02811   // CREATE two lists ( PREDICATES  and LOG OP )
02812 
02813   // Criterion
02814   TPythonDump()<<"aCriteria = []";
02815   std::list<SMESH::Predicate_ptr> aPredicates;
02816   std::list<int>                  aBinaries;
02817   for ( int i = 0, n = theCriteria.length(); i < n; i++ )
02818   {
02819     int         aCriterion    = theCriteria[ i ].Type;
02820     int         aCompare      = theCriteria[ i ].Compare;
02821     double      aThreshold    = theCriteria[ i ].Threshold;
02822     const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
02823     const char* aThresholdID  = theCriteria[ i ].ThresholdID;
02824     int         aUnary        = theCriteria[ i ].UnaryOp;
02825     int         aBinary       = theCriteria[ i ].BinaryOp;
02826     double      aTolerance    = theCriteria[ i ].Tolerance;
02827     ElementType aTypeOfElem   = theCriteria[ i ].TypeOfElement;
02828     long        aPrecision    = theCriteria[ i ].Precision;
02829 
02830     {
02831       TPythonDump pd;
02832       pd << "aCriterion = SMESH.Filter.Criterion("
02833          << aCriterion    << ", "
02834          << aCompare      << ", "
02835          << aThreshold    << ", '"
02836          << aThresholdStr << "', '";
02837       if (aThresholdID) pd << aThresholdID;
02838       pd                  << "', "
02839          << aUnary        << ", "
02840          << aBinary       << ", "
02841          << aTolerance    << ", "
02842          << aTypeOfElem   << ", "
02843          << aPrecision    << ")";
02844     }
02845     TPythonDump pd;
02846 
02847     SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
02848     SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
02849 
02850     switch ( aCriterion )
02851     {
02852       // Functors
02853 
02854       case SMESH::FT_MultiConnection:
02855         aFunctor = aFilterMgr->CreateMultiConnection();
02856         break;
02857       case SMESH::FT_MultiConnection2D:
02858         aFunctor = aFilterMgr->CreateMultiConnection2D();
02859         break;
02860       case SMESH::FT_Length:
02861         aFunctor = aFilterMgr->CreateLength();
02862         break;
02863       case SMESH::FT_Length2D:
02864         aFunctor = aFilterMgr->CreateLength2D();
02865         break;
02866       case SMESH::FT_AspectRatio:
02867         aFunctor = aFilterMgr->CreateAspectRatio();
02868         break;
02869       case SMESH::FT_AspectRatio3D:
02870         aFunctor = aFilterMgr->CreateAspectRatio3D();
02871         break;
02872       case SMESH::FT_Warping:
02873         aFunctor = aFilterMgr->CreateWarping();
02874         break;
02875       case SMESH::FT_MinimumAngle:
02876         aFunctor = aFilterMgr->CreateMinimumAngle();
02877         break;
02878       case SMESH::FT_Taper:
02879         aFunctor = aFilterMgr->CreateTaper();
02880         break;
02881       case SMESH::FT_Skew:
02882         aFunctor = aFilterMgr->CreateSkew();
02883         break;
02884       case SMESH::FT_Area:
02885         aFunctor = aFilterMgr->CreateArea();
02886         break;
02887       case SMESH::FT_Volume3D:
02888         aFunctor = aFilterMgr->CreateVolume3D();
02889         break;
02890       case SMESH::FT_MaxElementLength2D:
02891         aFunctor = aFilterMgr->CreateMaxElementLength2D();
02892         break;
02893       case SMESH::FT_MaxElementLength3D:
02894         aFunctor = aFilterMgr->CreateMaxElementLength3D();
02895         break;
02896 
02897       // Predicates
02898 
02899       case SMESH::FT_FreeBorders:
02900         aPredicate = aFilterMgr->CreateFreeBorders();
02901         break;
02902       case SMESH::FT_FreeEdges:
02903         aPredicate = aFilterMgr->CreateFreeEdges();
02904         break;
02905       case SMESH::FT_FreeFaces:
02906         aPredicate = aFilterMgr->CreateFreeFaces();
02907         break;
02908       case SMESH::FT_FreeNodes:
02909         aPredicate = aFilterMgr->CreateFreeNodes();
02910         break;
02911       case SMESH::FT_EqualNodes:
02912         {
02913           SMESH::EqualNodes_ptr pred = aFilterMgr->CreateEqualNodes();
02914           pred->SetTolerance( aTolerance );
02915           aPredicate = pred;
02916           break;
02917         }
02918       case SMESH::FT_EqualEdges:
02919         aPredicate = aFilterMgr->CreateEqualEdges();
02920         break;
02921       case SMESH::FT_EqualFaces:
02922         aPredicate = aFilterMgr->CreateEqualFaces();
02923         break;
02924       case SMESH::FT_EqualVolumes:
02925         aPredicate = aFilterMgr->CreateEqualVolumes();
02926         break;
02927       case SMESH::FT_BelongToGeom:
02928         {
02929           SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
02930           tmpPred->SetElementType( aTypeOfElem );
02931           tmpPred->SetShape( aThresholdID, aThresholdStr );
02932           tmpPred->SetTolerance( aTolerance );
02933           aPredicate = tmpPred;
02934         }
02935         break;
02936       case SMESH::FT_BelongToPlane:
02937       case SMESH::FT_BelongToCylinder:
02938       case SMESH::FT_BelongToGenSurface:
02939         {
02940           SMESH::BelongToSurface_ptr tmpPred;
02941           switch ( aCriterion ) {
02942           case SMESH::FT_BelongToPlane:
02943             tmpPred = aFilterMgr->CreateBelongToPlane(); break;
02944           case SMESH::FT_BelongToCylinder:
02945             tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
02946           default:
02947             tmpPred = aFilterMgr->CreateBelongToGenSurface();
02948           }
02949           tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
02950           tmpPred->SetTolerance( aTolerance );
02951           aPredicate = tmpPred;
02952         }
02953         break;
02954       case SMESH::FT_LyingOnGeom:
02955         {
02956           SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
02957           tmpPred->SetElementType( aTypeOfElem );
02958           tmpPred->SetShape( aThresholdID, aThresholdStr );
02959           tmpPred->SetTolerance( aTolerance );
02960           aPredicate = tmpPred;
02961         }
02962         break;
02963       case SMESH::FT_RangeOfIds:
02964         {
02965           SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
02966           tmpPred->SetRangeStr( aThresholdStr );
02967           tmpPred->SetElementType( aTypeOfElem );
02968           aPredicate = tmpPred;
02969         }
02970         break;
02971       case SMESH::FT_BadOrientedVolume:
02972         {
02973           aPredicate = aFilterMgr->CreateBadOrientedVolume();
02974         }
02975         break;
02976       case SMESH::FT_BareBorderVolume:
02977         {
02978           aPredicate = aFilterMgr->CreateBareBorderVolume();
02979         }
02980         break;
02981       case SMESH::FT_BareBorderFace:
02982         {
02983           aPredicate = aFilterMgr->CreateBareBorderFace();
02984         }
02985         break;
02986       case SMESH::FT_OverConstrainedVolume:
02987         {
02988           aPredicate = aFilterMgr->CreateOverConstrainedVolume();
02989         }
02990         break;
02991       case SMESH::FT_OverConstrainedFace:
02992         {
02993           aPredicate = aFilterMgr->CreateOverConstrainedFace();
02994         }
02995         break;
02996       case SMESH::FT_LinearOrQuadratic:
02997         {
02998           SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
02999           tmpPred->SetElementType( aTypeOfElem );
03000           aPredicate = tmpPred;
03001           break;
03002         }
03003       case SMESH::FT_GroupColor:
03004         {
03005           SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor();
03006           tmpPred->SetElementType( aTypeOfElem );
03007           tmpPred->SetColorStr( aThresholdStr );
03008           aPredicate = tmpPred;
03009           break;
03010         }
03011       case SMESH::FT_ElemGeomType:
03012         {
03013           SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType();
03014           tmpPred->SetElementType( aTypeOfElem );
03015           tmpPred->SetGeometryType( (GeometryType)(int)(aThreshold + 0.5) );
03016           aPredicate = tmpPred;
03017           break;
03018         }
03019       case SMESH::FT_CoplanarFaces:
03020         {
03021           SMESH::CoplanarFaces_ptr tmpPred = aFilterMgr->CreateCoplanarFaces();
03022           tmpPred->SetFace( atol (aThresholdID ));
03023           tmpPred->SetTolerance( aTolerance );
03024           aPredicate = tmpPred;
03025           break;
03026         }
03027 
03028       default:
03029         continue;
03030     }
03031 
03032     // Comparator
03033     if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
03034     {
03035       SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
03036 
03037       if ( aCompare == SMESH::FT_LessThan )
03038         aComparator = aFilterMgr->CreateLessThan();
03039       else if ( aCompare == SMESH::FT_MoreThan )
03040         aComparator = aFilterMgr->CreateMoreThan();
03041       else if ( aCompare == SMESH::FT_EqualTo )
03042         aComparator = aFilterMgr->CreateEqualTo();
03043       else
03044         continue;
03045 
03046       aComparator->SetNumFunctor( aFunctor );
03047       aComparator->SetMargin( aThreshold );
03048 
03049       if ( aCompare == FT_EqualTo )
03050       {
03051         SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
03052         anEqualTo->SetTolerance( aTolerance );
03053       }
03054 
03055       aPredicate = aComparator;
03056 
03057       aFunctor->SetPrecision( aPrecision );
03058     }
03059 
03060     // Logical not
03061     if ( aUnary == FT_LogicalNOT )
03062     {
03063       SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
03064       aNotPred->SetPredicate( aPredicate );
03065       aPredicate = aNotPred;
03066     }
03067 
03068     // logical op
03069     aPredicates.push_back( aPredicate );
03070     aBinaries.push_back( aBinary );
03071     pd <<"aCriteria.append(aCriterion)";
03072 
03073   } // end of for
03074   TPythonDump pd; pd<<this<<".SetCriteria(aCriteria)";
03075 
03076   // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
03077 
03078   // combine all "AND" operations
03079 
03080   std::list<SMESH::Predicate_ptr> aResList;
03081 
03082   std::list<SMESH::Predicate_ptr>::iterator aPredIter;
03083   std::list<int>::iterator                  aBinaryIter;
03084 
03085   SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
03086   int aPrevBinary = SMESH::FT_Undefined;
03087 
03088   for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
03089         aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
03090         ++aPredIter, ++aBinaryIter )
03091   {
03092     int aCurrBinary = *aBinaryIter;
03093 
03094     SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
03095 
03096     if ( aPrevBinary == SMESH::FT_LogicalAND )
03097     {
03098 
03099       SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
03100       aBinaryPred->SetPredicate1( aPrevPredicate );
03101       aBinaryPred->SetPredicate2( *aPredIter );
03102       aCurrPred = aBinaryPred;
03103     }
03104     else
03105       aCurrPred = *aPredIter;
03106 
03107     if ( aCurrBinary != SMESH::FT_LogicalAND )
03108       aResList.push_back( aCurrPred );
03109 
03110     aPrevPredicate = aCurrPred;
03111     aPrevBinary = aCurrBinary;
03112   }
03113 
03114   // combine all "OR" operations
03115 
03116   SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
03117 
03118   if ( aResList.size() == 1 )
03119     aResPredicate = *aResList.begin();
03120   else if ( aResList.size() > 1 )
03121   {
03122     std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
03123     aResPredicate = *anIter;
03124     anIter++;
03125     for ( ; anIter != aResList.end(); ++anIter )
03126     {
03127       SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
03128       aBinaryPred->SetPredicate1( aResPredicate );
03129       aBinaryPred->SetPredicate2( *anIter );
03130       aResPredicate = aBinaryPred;
03131     }
03132   }
03133 
03134   SetPredicate( aResPredicate );
03135 
03136   return !aResPredicate->_is_nil();
03137 }
03138 
03139 //=======================================================================
03140 // name    : Filter_i::GetPredicate_i
03141 // Purpose : Get implementation of predicate
03142 //=======================================================================
03143 Predicate_i* Filter_i::GetPredicate_i()
03144 {
03145   return myPredicate;
03146 }
03147 
03148 //=======================================================================
03149 // name    : Filter_i::GetPredicate
03150 // Purpose : Get predicate
03151 //=======================================================================
03152 Predicate_ptr Filter_i::GetPredicate()
03153 {
03154   if ( myPredicate == 0 )
03155     return SMESH::Predicate::_nil();
03156   else
03157   {
03158     SMESH::Predicate_var anObj = myPredicate->_this();
03159     // if ( SMESH::Functor_i* fun = SMESH::DownCast<SMESH::Functor_i*>( anObj ))
03160     //   TPythonDump() << fun << " = " << this << ".GetPredicate()";
03161     return anObj._retn();
03162   }
03163 }
03164 
03165 /*
03166                             FILTER LIBRARY
03167 */
03168 
03169 #define ATTR_TYPE          "type"
03170 #define ATTR_COMPARE       "compare"
03171 #define ATTR_THRESHOLD     "threshold"
03172 #define ATTR_UNARY         "unary"
03173 #define ATTR_BINARY        "binary"
03174 #define ATTR_THRESHOLD_STR "threshold_str"
03175 #define ATTR_TOLERANCE     "tolerance"
03176 #define ATTR_ELEMENT_TYPE  "ElementType"
03177 
03178 //=======================================================================
03179 // name    : toString
03180 // Purpose : Convert bool to LDOMString
03181 //=======================================================================
03182 static inline LDOMString toString( CORBA::Boolean val )
03183 {
03184   return val ? "logical not" : "";
03185 }
03186 
03187 //=======================================================================
03188 // name    : toBool
03189 // Purpose : Convert LDOMString to bool
03190 //=======================================================================
03191 static inline bool toBool( const LDOMString& theStr )
03192 {
03193   return theStr.equals( "logical not" );
03194 }
03195 
03196 //=======================================================================
03197 // name    : toString
03198 // Purpose : Convert double to LDOMString
03199 //=======================================================================
03200 static inline LDOMString toString( CORBA::Double val )
03201 {
03202   char a[ 255 ];
03203   sprintf( a, "%e", val );
03204   return LDOMString( a );
03205 }
03206 
03207 //=======================================================================
03208 // name    : toDouble
03209 // Purpose : Convert LDOMString to double
03210 //=======================================================================
03211 static inline double toDouble( const LDOMString& theStr )
03212 {
03213   return atof( theStr.GetString() );
03214 }
03215 
03216 //=======================================================================
03217 // name    : toString
03218 // Purpose : Convert functor type to LDOMString
03219 //=======================================================================
03220 static inline LDOMString toString( CORBA::Long theType )
03221 {
03222   switch ( theType )
03223   {
03224     case FT_AspectRatio     : return "Aspect ratio";
03225     case FT_Warping         : return "Warping";
03226     case FT_MinimumAngle    : return "Minimum angle";
03227     case FT_Taper           : return "Taper";
03228     case FT_Skew            : return "Skew";
03229     case FT_Area            : return "Area";
03230     case FT_Volume3D        : return "Volume3D";
03231     case FT_MaxElementLength2D: return "Max element length 2D";
03232     case FT_MaxElementLength3D: return "Max element length 3D";
03233     case FT_BelongToGeom    : return "Belong to Geom";
03234     case FT_BelongToPlane   : return "Belong to Plane";
03235     case FT_BelongToCylinder: return "Belong to Cylinder";
03236     case FT_BelongToGenSurface: return "Belong to Generic Surface";
03237     case FT_LyingOnGeom     : return "Lying on Geom";
03238     case FT_BadOrientedVolume:return "Bad Oriented Volume";
03239     case FT_BareBorderVolume: return "Volumes with bare border";
03240     case FT_BareBorderFace  : return "Faces with bare border";
03241     case FT_OverConstrainedVolume: return "Over-constrained Volumes";
03242     case FT_OverConstrainedFace  : return "Over-constrained Faces";
03243     case FT_RangeOfIds      : return "Range of IDs";
03244     case FT_FreeBorders     : return "Free borders";
03245     case FT_FreeEdges       : return "Free edges";
03246     case FT_FreeFaces       : return "Free faces";
03247     case FT_FreeNodes       : return "Free nodes";
03248     case FT_EqualNodes      : return "Equal nodes";
03249     case FT_EqualEdges      : return "Equal edges";
03250     case FT_EqualFaces      : return "Equal faces";
03251     case FT_EqualVolumes    : return "Equal volumes";
03252     case FT_MultiConnection : return "Borders at multi-connections";
03253     case FT_MultiConnection2D:return "Borders at multi-connections 2D";
03254     case FT_Length          : return "Length";
03255     case FT_Length2D        : return "Length 2D";
03256     case FT_LessThan        : return "Less than";
03257     case FT_MoreThan        : return "More than";
03258     case FT_EqualTo         : return "Equal to";
03259     case FT_LogicalNOT      : return "Not";
03260     case FT_LogicalAND      : return "And";
03261     case FT_LogicalOR       : return "Or";
03262     case FT_GroupColor      : return "Color of Group";
03263     case FT_LinearOrQuadratic : return "Linear or Quadratic";
03264     case FT_ElemGeomType    : return "Element geomtry type";
03265     case FT_Undefined       : return "";
03266     default                 : return "";
03267   }
03268 }
03269 
03270 //=======================================================================
03271 // name    : toFunctorType
03272 // Purpose : Convert LDOMString to functor type
03273 //=======================================================================
03274 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
03275 {
03276   if      ( theStr.equals( "Aspect ratio"                 ) ) return FT_AspectRatio;
03277   else if ( theStr.equals( "Warping"                      ) ) return FT_Warping;
03278   else if ( theStr.equals( "Minimum angle"                ) ) return FT_MinimumAngle;
03279   else if ( theStr.equals( "Taper"                        ) ) return FT_Taper;
03280   else if ( theStr.equals( "Skew"                         ) ) return FT_Skew;
03281   else if ( theStr.equals( "Area"                         ) ) return FT_Area;
03282   else if ( theStr.equals( "Volume3D"                     ) ) return FT_Volume3D;
03283   else if ( theStr.equals( "Max element length 2D"        ) ) return FT_MaxElementLength2D;
03284   else if ( theStr.equals( "Max element length 3D"        ) ) return FT_MaxElementLength3D;
03285   else if ( theStr.equals( "Belong to Geom"               ) ) return FT_BelongToGeom;
03286   else if ( theStr.equals( "Belong to Plane"              ) ) return FT_BelongToPlane;
03287   else if ( theStr.equals( "Belong to Cylinder"           ) ) return FT_BelongToCylinder;
03288   else if ( theStr.equals( "Belong to Generic Surface"    ) ) return FT_BelongToGenSurface;
03289   else if ( theStr.equals( "Lying on Geom"                ) ) return FT_LyingOnGeom;
03290   else if ( theStr.equals( "Free borders"                 ) ) return FT_FreeBorders;
03291   else if ( theStr.equals( "Free edges"                   ) ) return FT_FreeEdges;
03292   else if ( theStr.equals( "Free faces"                   ) ) return FT_FreeFaces;
03293   else if ( theStr.equals( "Free nodes"                   ) ) return FT_FreeNodes;
03294   else if ( theStr.equals( "Equal nodes"                  ) ) return FT_EqualNodes;
03295   else if ( theStr.equals( "Equal edges"                  ) ) return FT_EqualEdges;
03296   else if ( theStr.equals( "Equal faces"                  ) ) return FT_EqualFaces;
03297   else if ( theStr.equals( "Equal volumes"                ) ) return FT_EqualVolumes;
03298   else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
03299   //  else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
03300   else if ( theStr.equals( "Length"                       ) ) return FT_Length;
03301   //  else if ( theStr.equals( "Length2D"                     ) ) return FT_Length2D;
03302   else if ( theStr.equals( "Range of IDs"                 ) ) return FT_RangeOfIds;
03303   else if ( theStr.equals( "Bad Oriented Volume"          ) ) return FT_BadOrientedVolume;
03304   else if ( theStr.equals( "Volumes with bare border"     ) ) return FT_BareBorderVolume;
03305   else if ( theStr.equals( "Faces with bare border"       ) ) return FT_BareBorderFace;
03306   else if ( theStr.equals( "Over-constrained Volumes"     ) ) return FT_OverConstrainedVolume;
03307   else if ( theStr.equals( "Over-constrained Faces"       ) ) return FT_OverConstrainedFace;
03308   else if ( theStr.equals( "Less than"                    ) ) return FT_LessThan;
03309   else if ( theStr.equals( "More than"                    ) ) return FT_MoreThan;
03310   else if ( theStr.equals( "Equal to"                     ) ) return FT_EqualTo;
03311   else if ( theStr.equals( "Not"                          ) ) return FT_LogicalNOT;
03312   else if ( theStr.equals( "And"                          ) ) return FT_LogicalAND;
03313   else if ( theStr.equals( "Or"                           ) ) return FT_LogicalOR;
03314   else if ( theStr.equals( "Color of Group"               ) ) return FT_GroupColor;
03315   else if ( theStr.equals( "Linear or Quadratic"          ) ) return FT_LinearOrQuadratic;
03316   else if ( theStr.equals( "Element geomtry type"         ) ) return FT_ElemGeomType;
03317   else if ( theStr.equals( ""                             ) ) return FT_Undefined;
03318   else  return FT_Undefined;
03319 }
03320 
03321 //=======================================================================
03322 // name    : toFunctorType
03323 // Purpose : Convert LDOMString to value of ElementType enumeration
03324 //=======================================================================
03325 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
03326 {
03327   if      ( theStr.equals( "NODE"   ) ) return SMESH::NODE;
03328   else if ( theStr.equals( "EDGE"   ) ) return SMESH::EDGE;
03329   else if ( theStr.equals( "FACE"   ) ) return SMESH::FACE;
03330   else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
03331   else                                  return SMESH::ALL;
03332 }
03333 
03334 //=======================================================================
03335 // name    : toString
03336 // Purpose : Convert ElementType to string
03337 //=======================================================================
03338 static inline LDOMString toString( const SMESH::ElementType theType )
03339 {
03340   switch ( theType )
03341   {
03342     case SMESH::NODE   : return "NODE";
03343     case SMESH::EDGE   : return "EDGE";
03344     case SMESH::FACE   : return "FACE";
03345     case SMESH::VOLUME : return "VOLUME";
03346     case SMESH::ALL    : return "ALL";
03347     default            : return "";
03348   }
03349 }
03350 
03351 //=======================================================================
03352 // name    : findFilter
03353 // Purpose : Find filter in document
03354 //=======================================================================
03355 static LDOM_Element findFilter( const char* theFilterName,
03356                                 const LDOM_Document& theDoc,
03357                                 LDOM_Node* theParent = 0 )
03358 {
03359   LDOM_Element aRootElement = theDoc.getDocumentElement();
03360   if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
03361     return LDOM_Element();
03362 
03363   for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
03364         !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
03365   {
03366     for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
03367           !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
03368     {
03369       LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
03370       if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
03371            anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
03372       {
03373         if ( theParent != 0  )
03374           *theParent = aTypeNode;
03375         return (LDOM_Element&)aFilter;
03376       }
03377     }
03378   }
03379   return LDOM_Element();
03380 }
03381 
03382 //=======================================================================
03383 // name    : getSectionName
03384 // Purpose : Get name of section of filters
03385 //=======================================================================
03386 static const char* getSectionName( const ElementType theType )
03387 {
03388   switch ( theType )
03389   {
03390     case SMESH::NODE   : return "Filters for nodes";
03391     case SMESH::EDGE   : return "Filters for edges";
03392     case SMESH::FACE   : return "Filters for faces";
03393     case SMESH::VOLUME : return "Filters for volumes";
03394     case SMESH::ALL    : return "Filters for elements";
03395     default            : return "";
03396   }
03397 }
03398 
03399 //=======================================================================
03400 // name    : getSection
03401 // Purpose : Create section for filters corresponding to the entity type
03402 //=======================================================================
03403 static LDOM_Node getSection( const ElementType theType,
03404                              LDOM_Document&    theDoc,
03405                              const bool        toCreate = false )
03406 {
03407   LDOM_Element aRootElement = theDoc.getDocumentElement();
03408   if ( aRootElement.isNull() )
03409     return LDOM_Node();
03410 
03411   // Find section
03412   bool anExist = false;
03413   const char* aSectionName = getSectionName( theType );
03414   if ( strcmp( aSectionName, "" ) == 0 )
03415     return LDOM_Node();
03416 
03417   LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
03418   LDOM_Node aNode;
03419   for ( int i = 0, n = aSections.getLength(); i < n; i++ )
03420   {
03421     aNode = aSections.item( i );
03422     LDOM_Element& anItem = ( LDOM_Element& )aNode;
03423     if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
03424     {
03425       anExist = true;
03426       break;
03427     }
03428   }
03429 
03430   // Create new section if necessary
03431   if ( !anExist )
03432   {
03433     if ( toCreate )
03434     {
03435       LDOM_Element aNewItem = theDoc.createElement( "section" );
03436       aNewItem.setAttribute( "name", aSectionName );
03437       aRootElement.appendChild( aNewItem );
03438       return aNewItem;
03439     }
03440     else
03441       return LDOM_Node();
03442   }
03443   return
03444     aNode;
03445 }
03446 
03447 //=======================================================================
03448 // name    : createFilterItem
03449 // Purpose : Create filter item or LDOM document
03450 //=======================================================================
03451 static LDOM_Element createFilterItem( const char*       theName,
03452                                       SMESH::Filter_ptr theFilter,
03453                                       LDOM_Document&    theDoc )
03454 {
03455   // create new filter in document
03456   LDOM_Element aFilterItem = theDoc.createElement( "filter" );
03457   aFilterItem.setAttribute( "name", theName );
03458 
03459   // save filter criterions
03460   SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
03461 
03462   if ( !theFilter->GetCriteria( aCriteria ) )
03463     return LDOM_Element();
03464 
03465   for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
03466   {
03467     LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
03468     
03469     aCriterionItem.setAttribute( ATTR_TYPE         , toString(  aCriteria[ i ].Type) );
03470     aCriterionItem.setAttribute( ATTR_COMPARE      , toString(  aCriteria[ i ].Compare ) );
03471     aCriterionItem.setAttribute( ATTR_THRESHOLD    , toString(  aCriteria[ i ].Threshold ) );
03472     aCriterionItem.setAttribute( ATTR_UNARY        , toString(  aCriteria[ i ].UnaryOp ) );
03473     aCriterionItem.setAttribute( ATTR_BINARY       , toString(  aCriteria[ i ].BinaryOp ) );
03474 
03475     aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
03476     aCriterionItem.setAttribute( ATTR_TOLERANCE    , toString( aCriteria[ i ].Tolerance ) );
03477     aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
03478       toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
03479 
03480     aFilterItem.appendChild( aCriterionItem );
03481   }
03482 
03483   return aFilterItem;
03484 }
03485 
03486 //=======================================================================
03487 // name    : FilterLibrary_i::FilterLibrary_i
03488 // Purpose : Constructor
03489 //=======================================================================
03490 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
03491 {
03492   myFileName = strdup( theFileName );
03493   SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
03494   myFilterMgr = aFilterMgr->_this();
03495 
03496   LDOMParser aParser;
03497 
03498   // Try to use existing library file
03499   bool anExists = false;
03500   if ( !aParser.parse( myFileName ) )
03501   {
03502     myDoc = aParser.getDocument();
03503     anExists = true;
03504   }
03505   // Create a new XML document if it doesn't exist
03506   else
03507     myDoc = LDOM_Document::createDocument( LDOMString() );
03508 
03509   LDOM_Element aRootElement = myDoc.getDocumentElement();
03510   if ( aRootElement.isNull() )
03511   {
03512     // If the existing document is empty --> try to create a new one
03513     if ( anExists )
03514       myDoc = LDOM_Document::createDocument( LDOMString() );
03515   }
03516 }
03517 
03518 //=======================================================================
03519 // name    : FilterLibrary_i::FilterLibrary_i
03520 // Purpose : Constructor
03521 //=======================================================================
03522 FilterLibrary_i::FilterLibrary_i()
03523 {
03524   myFileName = 0;
03525   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
03526   myFilterMgr = aFilter->_this();
03527 
03528   myDoc = LDOM_Document::createDocument( LDOMString() );
03529 }
03530 
03531 FilterLibrary_i::~FilterLibrary_i()
03532 {
03533   delete myFileName;
03534   //TPythonDump()<<this<<".UnRegister()";
03535 }
03536 
03537 //=======================================================================
03538 // name    : FilterLibrary_i::Copy
03539 // Purpose : Create filter and initialize it with values from library
03540 //=======================================================================
03541 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
03542 {
03543   Filter_ptr aRes = Filter::_nil();
03544   LDOM_Node aFilter = findFilter( theFilterName, myDoc );
03545 
03546   if ( aFilter.isNull() )
03547     return aRes;
03548 
03549   std::list<SMESH::Filter::Criterion> aCriteria;
03550 
03551   for ( LDOM_Node aCritNode = aFilter.getFirstChild();
03552         !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
03553   {
03554     LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
03555 
03556     const char* aTypeStr      = aCrit->getAttribute( ATTR_TYPE          ).GetString();
03557     const char* aCompareStr   = aCrit->getAttribute( ATTR_COMPARE       ).GetString();
03558     const char* aUnaryStr     = aCrit->getAttribute( ATTR_UNARY         ).GetString();
03559     const char* aBinaryStr    = aCrit->getAttribute( ATTR_BINARY        ).GetString();
03560     const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE  ).GetString();
03561 
03562     SMESH::Filter::Criterion aCriterion = createCriterion();
03563 
03564     aCriterion.Type          = toFunctorType( aTypeStr );
03565     aCriterion.Compare       = toFunctorType( aCompareStr );
03566     aCriterion.UnaryOp       = toFunctorType( aUnaryStr );
03567     aCriterion.BinaryOp      = toFunctorType( aBinaryStr );
03568 
03569     aCriterion.TypeOfElement = toElementType( anElemTypeStr );
03570 
03571     LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
03572     int val = 0;
03573     aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
03574       ? val : atof( str.GetString() );
03575 
03576     str = aCrit->getAttribute( ATTR_TOLERANCE );
03577     aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
03578       ? val : atof( str.GetString() );
03579 
03580     str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
03581     if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
03582     {
03583       char a[ 255 ];
03584       sprintf( a, "%d", val );
03585       aCriterion.ThresholdStr = strdup( a );
03586     }
03587     else
03588       aCriterion.ThresholdStr = str.GetString();
03589 
03590     aCriteria.push_back( aCriterion );
03591   }
03592 
03593   SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
03594   aCriteriaVar->length( aCriteria.size() );
03595 
03596   CORBA::ULong i = 0;
03597   std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
03598 
03599   for( ; anIter != aCriteria.end(); ++anIter )
03600     aCriteriaVar[ i++ ] = *anIter;
03601 
03602   aRes = myFilterMgr->CreateFilter();
03603   aRes->SetCriteria( aCriteriaVar.inout() );
03604 
03605   TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
03606 
03607   return aRes;
03608 }
03609 
03610 //=======================================================================
03611 // name    : FilterLibrary_i::SetFileName
03612 // Purpose : Set file name for library
03613 //=======================================================================
03614 void FilterLibrary_i::SetFileName( const char* theFileName )
03615 {
03616   delete myFileName;
03617   myFileName = strdup( theFileName );
03618   TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
03619 }
03620 
03621 //=======================================================================
03622 // name    : FilterLibrary_i::GetFileName
03623 // Purpose : Get file name of library
03624 //=======================================================================
03625 char* FilterLibrary_i::GetFileName()
03626 {
03627   return CORBA::string_dup( myFileName );
03628 }
03629 
03630 //=======================================================================
03631 // name    : FilterLibrary_i::Add
03632 // Purpose : Add new filter to library
03633 //=======================================================================
03634 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
03635 {
03636   // if filter already in library or entry filter is null do nothing
03637   LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
03638   if ( !aFilterNode.isNull() || theFilter->_is_nil() )
03639     return false;
03640 
03641   // get section corresponding to the filter type
03642   ElementType anEntType = theFilter->GetElementType();
03643 
03644   LDOM_Node aSection = getSection( anEntType, myDoc, true );
03645   if ( aSection.isNull() )
03646     return false;
03647 
03648   // create filter item
03649   LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
03650   if ( aFilterItem.isNull() )
03651     return false;
03652   else
03653   {
03654     aSection.appendChild( aFilterItem );
03655     if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
03656       TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
03657     return true;
03658   }
03659 }
03660 
03661 //=======================================================================
03662 // name    : FilterLibrary_i::Add
03663 // Purpose : Add new filter to library
03664 //=======================================================================
03665 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
03666 {
03667   // if filter already in library or entry filter is null do nothing
03668   LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
03669   if ( !aFilterNode.isNull() )
03670     return false;
03671 
03672   LDOM_Node aSection = getSection( theType, myDoc, true );
03673   if ( aSection.isNull() )
03674     return false;
03675 
03676   // create filter item
03677   Filter_var aFilter = myFilterMgr->CreateFilter();
03678 
03679   LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
03680   if ( aFilterItem.isNull() )
03681     return false;
03682   else
03683   {
03684     aSection.appendChild( aFilterItem );
03685     TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
03686     return true;
03687   }
03688 }
03689 
03690 //=======================================================================
03691 // name    : FilterLibrary_i::Delete
03692 // Purpose : Delete filter from library
03693 //=======================================================================
03694 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
03695 {
03696   LDOM_Node aParentNode;
03697   LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
03698   if ( aFilterNode.isNull() || aParentNode.isNull() )
03699     return false;
03700 
03701   aParentNode.removeChild( aFilterNode );
03702   TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
03703   return true;
03704 }
03705 
03706 //=======================================================================
03707 // name      : FilterLibrary_i::Replace
03708 // Purpose   : Replace existing filter with entry filter.
03709 // IMPORTANT : If filter does not exist it is not created
03710 //=======================================================================
03711 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
03712                                          const char* theNewName,
03713                                          Filter_ptr  theFilter )
03714 {
03715   LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
03716   if ( aFilterItem.isNull() || theFilter->_is_nil() )
03717     return false;
03718 
03719   LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
03720   if ( aNewItem.isNull() )
03721     return false;
03722   else
03723   {
03724     aFilterItem.ReplaceElement( aNewItem );
03725     if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
03726       TPythonDump()<<this<<".Replace('"<<theFilterName<<"','"<<theNewName<<"',"<<aFilter<<")";
03727     return true;
03728   }
03729 }
03730 
03731 //=======================================================================
03732 // name    : FilterLibrary_i::Save
03733 // Purpose : Save library on disk
03734 //=======================================================================
03735 CORBA::Boolean FilterLibrary_i::Save()
03736 {
03737   if ( myFileName == 0 || strlen( myFileName ) == 0 )
03738     return false;
03739 
03740   FILE* aOutFile = fopen( myFileName, "wt" );
03741   if ( !aOutFile )
03742     return false;
03743 
03744   LDOM_XmlWriter aWriter( aOutFile );
03745   aWriter.SetIndentation( 2 );
03746   aWriter << myDoc;
03747   fclose( aOutFile );
03748 
03749   TPythonDump()<<this<<".Save()";
03750   return true;
03751 }
03752 
03753 //=======================================================================
03754 // name    : FilterLibrary_i::SaveAs
03755 // Purpose : Save library on disk
03756 //=======================================================================
03757 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
03758 {
03759   myFileName = strdup ( aFileName );
03760   TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
03761   return Save();
03762 }
03763 
03764 //=======================================================================
03765 // name    : FilterLibrary_i::IsPresent
03766 // Purpose : Verify whether filter is in library
03767 //=======================================================================
03768 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
03769 {
03770   return !findFilter( theFilterName, myDoc ).isNull();
03771 }
03772 
03773 //=======================================================================
03774 // name    : FilterLibrary_i::NbFilters
03775 // Purpose : Return amount of filters in library
03776 //=======================================================================
03777 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
03778 {
03779   string_array_var aNames = GetNames( theType );
03780   return aNames->length();
03781 }
03782 
03783 //=======================================================================
03784 // name    : FilterLibrary_i::GetNames
03785 // Purpose : Get names of filters from library
03786 //=======================================================================
03787 string_array* FilterLibrary_i::GetNames( ElementType theType )
03788 {
03789   string_array_var anArray = new string_array;
03790   TColStd_SequenceOfHAsciiString aSeq;
03791 
03792   LDOM_Node aSection = getSection( theType, myDoc, false );
03793 
03794   if ( !aSection.isNull() )
03795   {
03796     for ( LDOM_Node aFilter = aSection.getFirstChild();
03797           !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
03798     {
03799       LDOM_Element& anElem = ( LDOM_Element& )aFilter;
03800       aSeq.Append( new TCollection_HAsciiString(
03801          (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
03802     }
03803   }
03804 
03805   anArray->length( aSeq.Length() );
03806   for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
03807     anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
03808 
03809   return anArray._retn();
03810 }
03811 
03812 //=======================================================================
03813 // name    : FilterLibrary_i::GetAllNames
03814 // Purpose : Get names of filters from library
03815 //=======================================================================
03816 string_array* FilterLibrary_i::GetAllNames()
03817 {
03818   string_array_var aResArray = new string_array;
03819   for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
03820   {
03821     SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
03822 
03823     int aPrevLength = aResArray->length();
03824     aResArray->length( aPrevLength + aNames->length() );
03825     for ( int i = 0, n = aNames->length(); i < n; i++ )
03826       aResArray[ aPrevLength + i ] = aNames[ i ];
03827   }
03828 
03829   return aResArray._retn();
03830 }
03831 
03832 //================================================================================
03836 //================================================================================
03837 
03838 static const char** getFunctNames()
03839 {
03840   static const char* functName[ SMESH::FT_Undefined + 1 ] = {
03841     // IT's necessary to update this array according to enum FunctorType (SMESH_Filter.idl)
03842     // The order is IMPORTANT !!!
03843     "FT_AspectRatio", "FT_AspectRatio3D", "FT_Warping", "FT_MinimumAngle",
03844     "FT_Taper", "FT_Skew", "FT_Area", "FT_Volume3D", "FT_MaxElementLength2D",
03845     "FT_MaxElementLength3D", "FT_FreeBorders", "FT_FreeEdges", "FT_FreeNodes",
03846     "FT_FreeFaces","FT_EqualNodes","FT_EqualEdges","FT_EqualFaces","FT_EqualVolumes",
03847     "FT_MultiConnection", "FT_MultiConnection2D", "FT_Length",
03848     "FT_Length2D", "FT_BelongToGeom", "FT_BelongToPlane", "FT_BelongToCylinder",
03849     "FT_BelongToGenSurface", "FT_LyingOnGeom", "FT_RangeOfIds", "FT_BadOrientedVolume",
03850     "FT_BareBorderVolume", "FT_BareBorderFace", "FT_OverConstrainedVolume",
03851     "FT_OverConstrainedFace", "FT_LinearOrQuadratic", "FT_GroupColor", "FT_ElemGeomType",
03852     "FT_CoplanarFaces", "FT_LessThan", "FT_MoreThan", "FT_EqualTo", "FT_LogicalNOT",
03853     "FT_LogicalAND", "FT_LogicalOR", "FT_Undefined" };
03854   return functName;
03855 }
03856 
03857 //================================================================================
03861 //================================================================================
03862 
03863 const char* SMESH::FunctorTypeToString(SMESH::FunctorType ft)
03864 {
03865   if ( ft < 0 || ft > SMESH::FT_Undefined )
03866     return "FT_Undefined";
03867   return getFunctNames()[ ft ];
03868 }
03869 
03870 //================================================================================
03874 //================================================================================
03875 
03876 SMESH::FunctorType SMESH::StringToFunctorType(const char* str)
03877 {
03878   std::string name( str + 3 ); // skip "FT_"
03879   const char** functNames = getFunctNames();
03880   int ft = 0;
03881   for ( ; ft < SMESH::FT_Undefined; ++ft )
03882     if ( name == ( functNames[ft] + 3 ))
03883       break;
03884 
03885   //ASSERT( strcmp( str, FunctorTypeToString( SMESH::FunctorType( ft ))) == 0 );
03886 
03887   return SMESH::FunctorType( ft );
03888 }