1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_Filter_i.cxx
25 // Author : Alexey Petrov, OCC
29 #include "SMESH_Filter_i.hxx"
31 #include "SMESH_Gen_i.hxx"
32 #include "SMESH_PythonDump.hxx"
34 #include "SMDS_Mesh.hxx"
35 #include "SMDS_MeshNode.hxx"
36 #include "SMDS_MeshElement.hxx"
38 #include "SMESHDS_Mesh.hxx"
40 #include <LDOM_Document.hxx>
41 #include <LDOM_Element.hxx>
42 #include <LDOM_Node.hxx>
43 #include <LDOMString.hxx>
44 #include <LDOMParser.hxx>
45 #include <LDOM_XmlWriter.hxx>
46 #include <TCollection_HAsciiString.hxx>
47 #include <TColStd_ListIteratorOfListOfInteger.hxx>
48 #include <TColStd_ListOfInteger.hxx>
49 #include <TColStd_ListOfReal.hxx>
50 #include <TColStd_MapOfInteger.hxx>
51 #include <TColStd_SequenceOfHAsciiString.hxx>
52 #include <TColStd_ListIteratorOfListOfReal.hxx>
53 #include <Precision.hxx>
54 #include <BRep_Tool.hxx>
55 #include <TopoDS_Shape.hxx>
57 #include <TopoDS_Face.hxx>
58 #include <Geom_Plane.hxx>
59 #include <Geom_CylindricalSurface.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <OSD_Path.hxx>
62 #include <OSD_File.hxx>
64 using namespace SMESH;
65 using namespace SMESH::Controls;
71 GetPredicate( Predicate_ptr thePredicate )
73 return DownCast<Predicate_i*>(thePredicate);
80 Description : Predicate for verifying whether entiy belong to
81 specified geometrical support
84 Controls::BelongToGeom::BelongToGeom()
89 void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
91 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
94 void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
99 static bool IsContains( const SMESHDS_Mesh* theMeshDS,
100 const TopoDS_Shape& theShape,
101 const SMDS_MeshElement* theElem,
102 TopAbs_ShapeEnum theFindShapeEnum,
103 TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE )
105 TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
107 while( anExp.More() )
109 const TopoDS_Shape& aShape = anExp.Current();
110 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
111 if( aSubMesh->Contains( theElem ) )
119 bool Controls::BelongToGeom::IsSatisfy( long theId )
121 if ( myMeshDS == 0 || myShape.IsNull() )
124 if( myType == SMDSAbs_Node )
126 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
128 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
129 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
130 switch( aTypeOfPosition )
132 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
133 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
134 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
135 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
141 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
143 if( myType == SMDSAbs_All )
145 return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
146 IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
147 IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
148 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
150 else if( myType == anElem->GetType() )
154 case SMDSAbs_Edge : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
155 case SMDSAbs_Face : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
156 case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
157 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
166 void Controls::BelongToGeom::SetType( SMDSAbs_ElementType theType )
171 SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
176 TopoDS_Shape Controls::BelongToGeom::GetShape()
182 Controls::BelongToGeom::
190 Description : Predicate for verifying whether entiy lying or partially lying on
191 specified geometrical support
194 Controls::LyingOnGeom::LyingOnGeom()
199 void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
201 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
204 void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
209 bool Controls::LyingOnGeom::IsSatisfy( long theId )
211 if ( myMeshDS == 0 || myShape.IsNull() )
214 if( myType == SMDSAbs_Node )
216 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
218 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
219 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
220 switch( aTypeOfPosition )
222 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
223 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
224 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
225 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
231 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
233 if( myType == SMDSAbs_All )
235 return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
236 Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
237 Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
238 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
240 else if( myType == anElem->GetType() )
244 case SMDSAbs_Edge : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
245 case SMDSAbs_Face : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
246 case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
247 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
256 void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
261 SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
266 TopoDS_Shape Controls::LyingOnGeom::GetShape()
272 Controls::LyingOnGeom::
278 bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh* theMeshDS,
279 const TopoDS_Shape& theShape,
280 const SMDS_MeshElement* theElem,
281 TopAbs_ShapeEnum theFindShapeEnum,
282 TopAbs_ShapeEnum theAvoidShapeEnum )
284 if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
287 TopTools_IndexedMapOfShape aSubShapes;
288 TopExp::MapShapes( theShape, aSubShapes );
290 for (int i = 1; i <= aSubShapes.Extent(); i++)
292 const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
294 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
295 if( aSubMesh->Contains( theElem ) )
298 SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
299 while ( aNodeIt->more() )
301 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
302 SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
303 while ( anElemIt->more() )
305 const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
306 if (anElement == theElem)
322 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
324 SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
325 return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
330 toArray( const TColStd_ListOfInteger& aList )
332 SMESH::long_array_var anArray = new SMESH::long_array;
333 anArray->length( aList.Extent() );
334 TColStd_ListIteratorOfListOfInteger anIter( aList );
336 for( ; anIter.More(); anIter.Next() )
337 anArray[ i++ ] = anIter.Value();
339 return anArray._retn();
344 toArray( const TColStd_ListOfReal& aList )
346 SMESH::double_array_var anArray = new SMESH::double_array;
347 anArray->length( aList.Extent() );
348 TColStd_ListIteratorOfListOfReal anIter( aList );
350 for( ; anIter.More(); anIter.Next() )
351 anArray[ i++ ] = anIter.Value();
353 return anArray._retn();
356 static SMESH::Filter::Criterion createCriterion()
358 SMESH::Filter::Criterion aCriterion;
360 aCriterion.Type = FT_Undefined;
361 aCriterion.Compare = FT_Undefined;
362 aCriterion.Threshold = 0;
363 aCriterion.UnaryOp = FT_Undefined;
364 aCriterion.BinaryOp = FT_Undefined;
365 aCriterion.ThresholdStr = "";
366 aCriterion.ThresholdID = "";
367 aCriterion.Tolerance = Precision::Confusion();
368 aCriterion.TypeOfElement = SMESH::ALL;
369 aCriterion.Precision = -1;
374 static TopoDS_Shape getShapeByName( const char* theName )
378 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
379 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
380 if (!CORBA::is_nil(aStudy))
382 SALOMEDS::Study::ListOfSObject_var aList =
383 aStudy->FindObjectByName( theName, "GEOM" );
384 if ( aList->length() > 0 )
386 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
387 if ( !aGeomObj->_is_nil() )
389 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
390 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
396 return TopoDS_Shape();
399 static TopoDS_Shape getShapeByID( const char* theID )
401 if ( theID != 0 && theID!="" )
403 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
404 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
407 CORBA::Object_var obj = aStudy->ConvertIORToObject(theID);
408 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( obj );
410 if ( !aGeomObj->_is_nil() )
412 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
413 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
418 return TopoDS_Shape();
421 static char* getShapeNameByID ( const char* theID )
425 if ( theID != 0 && theID!="" )
427 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
428 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
431 SALOMEDS::SObject_var aSObj = aStudy->FindObjectIOR( theID );
432 SALOMEDS::GenericAttribute_var anAttr;
433 if ( !aSObj->_is_nil() && aSObj->FindAttribute( anAttr, "AttributeName") )
435 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
436 aName = aNameAttr->Value();
450 Description : An abstact class for all functors
452 Functor_i::Functor_i():
453 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
455 PortableServer::ObjectId_var anObjectId =
456 SMESH_Gen_i::GetPOA()->activate_object( this );
459 Functor_i::~Functor_i()
461 TPythonDump()<<this<<".Destroy()";
464 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
466 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
467 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
470 ElementType Functor_i::GetElementType()
472 return ( ElementType )myFunctorPtr->GetType();
477 Class : NumericalFunctor_i
478 Description : Base class for numerical functors
480 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
482 return myNumericalFunctorPtr->GetValue( theId );
485 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
487 myNumericalFunctorPtr->SetPrecision( thePrecision );
488 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
491 CORBA::Long NumericalFunctor_i::GetPrecision()
493 return myNumericalFunctorPtr->GetPrecision();
496 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
498 return myNumericalFunctorPtr;
503 Class : SMESH_MinimumAngle
504 Description : Functor for calculation of minimum angle
506 MinimumAngle_i::MinimumAngle_i()
508 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
509 myFunctorPtr = myNumericalFunctorPtr;
512 FunctorType MinimumAngle_i::GetFunctorType()
514 return SMESH::FT_MinimumAngle;
520 Description : Functor for calculating aspect ratio
522 AspectRatio_i::AspectRatio_i()
524 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
525 myFunctorPtr = myNumericalFunctorPtr;
528 FunctorType AspectRatio_i::GetFunctorType()
530 return SMESH::FT_AspectRatio;
535 Class : AspectRatio3D
536 Description : Functor for calculating aspect ratio 3D
538 AspectRatio3D_i::AspectRatio3D_i()
540 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
541 myFunctorPtr = myNumericalFunctorPtr;
544 FunctorType AspectRatio3D_i::GetFunctorType()
546 return SMESH::FT_AspectRatio3D;
552 Description : Functor for calculating warping
554 Warping_i::Warping_i()
556 myNumericalFunctorPtr.reset( new Controls::Warping() );
557 myFunctorPtr = myNumericalFunctorPtr;
560 FunctorType Warping_i::GetFunctorType()
562 return SMESH::FT_Warping;
568 Description : Functor for calculating taper
572 myNumericalFunctorPtr.reset( new Controls::Taper() );
573 myFunctorPtr = myNumericalFunctorPtr;
576 FunctorType Taper_i::GetFunctorType()
578 return SMESH::FT_Taper;
584 Description : Functor for calculating skew in degrees
588 myNumericalFunctorPtr.reset( new Controls::Skew() );
589 myFunctorPtr = myNumericalFunctorPtr;
592 FunctorType Skew_i::GetFunctorType()
594 return SMESH::FT_Skew;
599 Description : Functor for calculating area
603 myNumericalFunctorPtr.reset( new Controls::Area() );
604 myFunctorPtr = myNumericalFunctorPtr;
607 FunctorType Area_i::GetFunctorType()
609 return SMESH::FT_Area;
614 Description : Functor for calculating volume of 3D element
616 Volume3D_i::Volume3D_i()
618 myNumericalFunctorPtr.reset( new Controls::Volume() );
619 myFunctorPtr = myNumericalFunctorPtr;
622 FunctorType Volume3D_i::GetFunctorType()
624 return SMESH::FT_Volume3D;
629 Description : Functor for calculating length off edge
633 myNumericalFunctorPtr.reset( new Controls::Length() );
634 myFunctorPtr = myNumericalFunctorPtr;
637 FunctorType Length_i::GetFunctorType()
639 return SMESH::FT_Length;
644 Description : Functor for calculating length of edge
646 Length2D_i::Length2D_i()
648 myNumericalFunctorPtr.reset( new Controls::Length2D() );
649 myFunctorPtr = myNumericalFunctorPtr;
652 FunctorType Length2D_i::GetFunctorType()
654 return SMESH::FT_Length2D;
657 SMESH::Length2D::Values* Length2D_i::GetValues()
659 INFOS("Length2D_i::GetValues");
660 SMESH::Controls::Length2D::TValues aValues;
661 myLength2DPtr->GetValues( aValues );
663 long i = 0, iEnd = aValues.size();
665 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
667 SMESH::Controls::Length2D::TValues::const_iterator anIter;
668 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
670 const SMESH::Controls::Length2D::Value& aVal = *anIter;
671 SMESH::Length2D::Value &aValue = aResult[ i ];
673 aValue.myLength = aVal.myLength;
674 aValue.myPnt1 = aVal.myPntId[ 0 ];
675 aValue.myPnt2 = aVal.myPntId[ 1 ];
678 INFOS("Length2D_i::GetValuess~");
679 return aResult._retn();
683 Class : MultiConnection_i
684 Description : Functor for calculating number of faces conneted to the edge
686 MultiConnection_i::MultiConnection_i()
688 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
689 myFunctorPtr = myNumericalFunctorPtr;
692 FunctorType MultiConnection_i::GetFunctorType()
694 return SMESH::FT_MultiConnection;
698 Class : MultiConnection2D_i
699 Description : Functor for calculating number of faces conneted to the edge
701 MultiConnection2D_i::MultiConnection2D_i()
703 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
704 myFunctorPtr = myNumericalFunctorPtr;
707 FunctorType MultiConnection2D_i::GetFunctorType()
709 return SMESH::FT_MultiConnection2D;
712 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
714 INFOS("MultiConnection2D_i::GetValues");
715 SMESH::Controls::MultiConnection2D::MValues aValues;
716 myMulticonnection2DPtr->GetValues( aValues );
718 long i = 0, iEnd = aValues.size();
720 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
722 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
723 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
725 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
726 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
728 aValue.myPnt1 = aVal.myPntId[ 0 ];
729 aValue.myPnt2 = aVal.myPntId[ 1 ];
730 aValue.myNbConnects = (*anIter).second;
733 INFOS("Multiconnection2D_i::GetValuess~");
734 return aResult._retn();
744 Description : Base class for all predicates
746 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
748 return myPredicatePtr->IsSatisfy( theId );
751 Controls::PredicatePtr Predicate_i::GetPredicate()
753 return myPredicatePtr;
757 Class : BadOrientedVolume_i
758 Description : Verify whether a mesh volume is incorrectly oriented from
759 the point of view of MED convention
761 BadOrientedVolume_i::BadOrientedVolume_i()
763 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
764 myFunctorPtr = myPredicatePtr = control;
767 FunctorType BadOrientedVolume_i::GetFunctorType()
769 return SMESH::FT_BadOrientedVolume;
773 Class : BelongToGeom_i
774 Description : Predicate for selection on geometrical support
776 BelongToGeom_i::BelongToGeom_i()
778 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
779 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
784 BelongToGeom_i::~BelongToGeom_i()
790 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
792 if ( theGeom->_is_nil() )
794 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
795 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
796 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
797 myBelongToGeomPtr->SetGeom( aLocShape );
798 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
801 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
803 myBelongToGeomPtr->SetGeom( theShape );
806 void BelongToGeom_i::SetElementType(ElementType theType){
807 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
808 TPythonDump()<<this<<".SetElementType("<<theType<<")";
811 FunctorType BelongToGeom_i::GetFunctorType()
813 return SMESH::FT_BelongToGeom;
816 void BelongToGeom_i::SetShapeName( const char* theName )
819 myShapeName = strdup( theName );
820 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
821 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
824 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
827 myShapeName = strdup( theName );
830 myShapeID = strdup( theID );
834 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
835 myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
837 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
840 char* BelongToGeom_i::GetShapeName()
842 return CORBA::string_dup( myShapeName );
845 char* BelongToGeom_i::GetShapeID()
847 return CORBA::string_dup( myShapeID );
851 Class : BelongToSurface_i
852 Description : Predicate for selection on geometrical support
854 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
856 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
857 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
860 mySurfaceType = theSurfaceType;
863 BelongToSurface_i::~BelongToSurface_i()
869 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
871 if ( theGeom->_is_nil() )
873 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
874 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
875 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
877 if ( aLocShape.ShapeType() == TopAbs_FACE )
879 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
880 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
882 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
887 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
888 TPythonDump()<<this<<".SetSurface("<<theGeom<<",'"<<theType<<"')";
891 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
894 myShapeName = strdup( theName );
895 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
896 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
899 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
902 myShapeName = strdup( theName );
905 myShapeID = strdup( theID );
909 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
910 myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
912 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
915 char* BelongToSurface_i::GetShapeName()
917 return CORBA::string_dup( myShapeName );
920 char* BelongToSurface_i::GetShapeID()
922 return CORBA::string_dup( myShapeID );
925 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
927 myElementsOnSurfacePtr->SetTolerance( theToler );
928 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
931 CORBA::Double BelongToSurface_i::GetTolerance()
933 return myElementsOnSurfacePtr->GetTolerance();
937 Class : BelongToPlane_i
938 Description : Verify whether mesh element lie in pointed Geom planar object
941 BelongToPlane_i::BelongToPlane_i()
942 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
946 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
948 BelongToSurface_i::SetSurface( theGeom, theType );
949 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
952 FunctorType BelongToPlane_i::GetFunctorType()
954 return FT_BelongToPlane;
958 Class : BelongToCylinder_i
959 Description : Verify whether mesh element lie in pointed Geom planar object
962 BelongToCylinder_i::BelongToCylinder_i()
963 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
967 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
969 BelongToSurface_i::SetSurface( theGeom, theType );
970 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
973 FunctorType BelongToCylinder_i::GetFunctorType()
975 return FT_BelongToCylinder;
979 Class : LyingOnGeom_i
980 Description : Predicate for selection on geometrical support
982 LyingOnGeom_i::LyingOnGeom_i()
984 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
985 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
990 LyingOnGeom_i::~LyingOnGeom_i()
996 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
998 if ( theGeom->_is_nil() )
1000 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1001 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1002 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1003 myLyingOnGeomPtr->SetGeom( aLocShape );
1004 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1007 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1009 myLyingOnGeomPtr->SetGeom( theShape );
1012 void LyingOnGeom_i::SetElementType(ElementType theType){
1013 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1014 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1017 FunctorType LyingOnGeom_i::GetFunctorType()
1019 return SMESH::FT_LyingOnGeom;
1022 void LyingOnGeom_i::SetShapeName( const char* theName )
1025 myShapeName = strdup( theName );
1026 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1027 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1030 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1033 myShapeName = strdup( theName );
1036 myShapeID = strdup( theID );
1040 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1041 myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
1043 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1046 char* LyingOnGeom_i::GetShapeName()
1048 return CORBA::string_dup( myShapeName );
1051 char* LyingOnGeom_i::GetShapeID()
1053 return CORBA::string_dup( myShapeID );
1057 Class : FreeBorders_i
1058 Description : Predicate for free borders
1060 FreeBorders_i::FreeBorders_i()
1062 myPredicatePtr.reset(new Controls::FreeBorders());
1063 myFunctorPtr = myPredicatePtr;
1066 FunctorType FreeBorders_i::GetFunctorType()
1068 return SMESH::FT_FreeBorders;
1073 Description : Predicate for free borders
1075 FreeEdges_i::FreeEdges_i()
1076 : myFreeEdgesPtr( new Controls::FreeEdges() )
1078 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1081 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1083 INFOS("FreeEdges_i::GetBorders");
1084 SMESH::Controls::FreeEdges::TBorders aBorders;
1085 myFreeEdgesPtr->GetBoreders( aBorders );
1087 long i = 0, iEnd = aBorders.size();
1089 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders(iEnd);
1091 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1092 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1094 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1095 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1097 aBorder.myElemId = aBord.myElemId;
1098 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1099 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1102 INFOS("FreeEdges_i::GetBorders~");
1103 return aResult._retn();
1106 FunctorType FreeEdges_i::GetFunctorType()
1108 return SMESH::FT_FreeEdges;
1112 Class : RangeOfIds_i
1113 Description : Predicate for Range of Ids.
1114 Range may be specified with two ways.
1115 1. Using AddToRange method
1116 2. With SetRangeStr method. Parameter of this method is a string
1117 like as "1,2,3,50-60,63,67,70-"
1120 RangeOfIds_i::RangeOfIds_i()
1122 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1123 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1126 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1128 CORBA::Long iEnd = theIds.length();
1129 for ( CORBA::Long i = 0; i < iEnd; i++ )
1130 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1131 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1134 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1136 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1137 return myRangeOfIdsPtr->SetRangeStr(
1138 TCollection_AsciiString( (Standard_CString)theRange ) );
1141 char* RangeOfIds_i::GetRangeStr()
1143 TCollection_AsciiString aStr;
1144 myRangeOfIdsPtr->GetRangeStr( aStr );
1145 return CORBA::string_dup( aStr.ToCString() );
1148 void RangeOfIds_i::SetElementType( ElementType theType )
1150 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1151 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1154 FunctorType RangeOfIds_i::GetFunctorType()
1156 return SMESH::FT_RangeOfIds;
1160 Class : Comparator_i
1161 Description : Base class for comparators
1163 Comparator_i::Comparator_i():
1164 myNumericalFunctor( NULL )
1167 Comparator_i::~Comparator_i()
1169 if ( myNumericalFunctor )
1170 myNumericalFunctor->Destroy();
1173 void Comparator_i::SetMargin( CORBA::Double theValue )
1175 myComparatorPtr->SetMargin( theValue );
1176 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1179 CORBA::Double Comparator_i::GetMargin()
1181 return myComparatorPtr->GetMargin();
1184 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1186 if ( myNumericalFunctor )
1187 myNumericalFunctor->Destroy();
1189 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1191 if ( myNumericalFunctor )
1193 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1194 myNumericalFunctor->Register();
1195 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1199 Controls::ComparatorPtr Comparator_i::GetComparator()
1201 return myComparatorPtr;
1204 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1206 return myNumericalFunctor;
1212 Description : Comparator "<"
1214 LessThan_i::LessThan_i()
1216 myComparatorPtr.reset( new Controls::LessThan() );
1217 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1220 FunctorType LessThan_i::GetFunctorType()
1222 return SMESH::FT_LessThan;
1228 Description : Comparator ">"
1230 MoreThan_i::MoreThan_i()
1232 myComparatorPtr.reset( new Controls::MoreThan() );
1233 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1236 FunctorType MoreThan_i::GetFunctorType()
1238 return SMESH::FT_MoreThan;
1244 Description : Comparator "="
1246 EqualTo_i::EqualTo_i()
1247 : myEqualToPtr( new Controls::EqualTo() )
1249 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1252 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1254 myEqualToPtr->SetTolerance( theToler );
1255 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1258 CORBA::Double EqualTo_i::GetTolerance()
1260 return myEqualToPtr->GetTolerance();
1263 FunctorType EqualTo_i::GetFunctorType()
1265 return SMESH::FT_EqualTo;
1269 Class : LogicalNOT_i
1270 Description : Logical NOT predicate
1272 LogicalNOT_i::LogicalNOT_i()
1273 : myPredicate( NULL ),
1274 myLogicalNOTPtr( new Controls::LogicalNOT() )
1276 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1279 LogicalNOT_i::~LogicalNOT_i()
1282 myPredicate->Destroy();
1285 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1288 myPredicate->Destroy();
1290 myPredicate = SMESH::GetPredicate(thePredicate);
1293 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1294 myPredicate->Register();
1295 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1299 FunctorType LogicalNOT_i::GetFunctorType()
1301 return SMESH::FT_LogicalNOT;
1304 Predicate_i* LogicalNOT_i::GetPredicate_i()
1311 Class : LogicalBinary_i
1312 Description : Base class for binary logical predicate
1314 LogicalBinary_i::LogicalBinary_i()
1315 : myPredicate1( NULL ),
1316 myPredicate2( NULL )
1319 LogicalBinary_i::~LogicalBinary_i()
1322 myPredicate1->Destroy();
1325 myPredicate2->Destroy();
1328 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1331 myPredicate1->SetMesh( theMesh );
1334 myPredicate2->SetMesh( theMesh );
1337 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1340 myPredicate1->Destroy();
1342 myPredicate1 = SMESH::GetPredicate(thePredicate);
1344 if ( myPredicate1 ){
1345 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1346 myPredicate1->Register();
1347 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1351 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1354 myPredicate2->Destroy();
1356 myPredicate2 = SMESH::GetPredicate(thePredicate);
1358 if ( myPredicate2 ){
1359 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1360 myPredicate2->Register();
1361 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1365 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1367 return myLogicalBinaryPtr;
1370 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1372 return myPredicate1;
1374 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1376 return myPredicate2;
1381 Class : LogicalAND_i
1382 Description : Logical AND
1384 LogicalAND_i::LogicalAND_i()
1386 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1387 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1390 FunctorType LogicalAND_i::GetFunctorType()
1392 return SMESH::FT_LogicalAND;
1398 Description : Logical OR
1400 LogicalOR_i::LogicalOR_i()
1402 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1403 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1406 FunctorType LogicalOR_i::GetFunctorType()
1408 return SMESH::FT_LogicalOR;
1416 FilterManager_i::FilterManager_i()
1417 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1419 PortableServer::ObjectId_var anObjectId =
1420 SMESH_Gen_i::GetPOA()->activate_object( this );
1424 FilterManager_i::~FilterManager_i()
1426 TPythonDump()<<this<<".Destroy()";
1430 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1432 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1433 SMESH::MinimumAngle_var anObj = aServant->_this();
1434 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1435 return anObj._retn();
1439 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1441 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1442 SMESH::AspectRatio_var anObj = aServant->_this();
1443 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1444 return anObj._retn();
1448 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1450 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1451 SMESH::AspectRatio3D_var anObj = aServant->_this();
1452 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1453 return anObj._retn();
1457 Warping_ptr FilterManager_i::CreateWarping()
1459 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1460 SMESH::Warping_var anObj = aServant->_this();
1461 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1462 return anObj._retn();
1466 Taper_ptr FilterManager_i::CreateTaper()
1468 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1469 SMESH::Taper_var anObj = aServant->_this();
1470 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1471 return anObj._retn();
1475 Skew_ptr FilterManager_i::CreateSkew()
1477 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1478 SMESH::Skew_var anObj = aServant->_this();
1479 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1480 return anObj._retn();
1484 Area_ptr FilterManager_i::CreateArea()
1486 SMESH::Area_i* aServant = new SMESH::Area_i();
1487 SMESH::Area_var anObj = aServant->_this();
1488 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1489 return anObj._retn();
1493 Volume3D_ptr FilterManager_i::CreateVolume3D()
1495 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
1496 SMESH::Volume3D_var anObj = aServant->_this();
1497 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
1498 return anObj._retn();
1502 Length_ptr FilterManager_i::CreateLength()
1504 SMESH::Length_i* aServant = new SMESH::Length_i();
1505 SMESH::Length_var anObj = aServant->_this();
1506 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1507 return anObj._retn();
1510 Length2D_ptr FilterManager_i::CreateLength2D()
1512 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1513 SMESH::Length2D_var anObj = aServant->_this();
1514 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1515 return anObj._retn();
1518 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1520 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1521 SMESH::MultiConnection_var anObj = aServant->_this();
1522 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1523 return anObj._retn();
1526 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1528 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1529 SMESH::MultiConnection2D_var anObj = aServant->_this();
1530 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
1531 return anObj._retn();
1534 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1536 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1537 SMESH::BelongToGeom_var anObj = aServant->_this();
1538 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
1539 return anObj._retn();
1542 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1544 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1545 SMESH::BelongToPlane_var anObj = aServant->_this();
1546 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
1547 return anObj._retn();
1550 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1552 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1553 SMESH::BelongToCylinder_var anObj = aServant->_this();
1554 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
1555 return anObj._retn();
1558 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
1560 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
1561 SMESH::LyingOnGeom_var anObj = aServant->_this();
1562 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
1563 return anObj._retn();
1566 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1568 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1569 SMESH::FreeBorders_var anObj = aServant->_this();
1570 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
1571 return anObj._retn();
1574 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1576 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1577 SMESH::FreeEdges_var anObj = aServant->_this();
1578 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
1579 return anObj._retn();
1582 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1584 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1585 SMESH::RangeOfIds_var anObj = aServant->_this();
1586 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
1587 return anObj._retn();
1590 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
1592 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
1593 SMESH::BadOrientedVolume_var anObj = aServant->_this();
1594 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
1595 return anObj._retn();
1598 LessThan_ptr FilterManager_i::CreateLessThan()
1600 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1601 SMESH::LessThan_var anObj = aServant->_this();
1602 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
1603 return anObj._retn();
1607 MoreThan_ptr FilterManager_i::CreateMoreThan()
1609 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1610 SMESH::MoreThan_var anObj = aServant->_this();
1611 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
1612 return anObj._retn();
1615 EqualTo_ptr FilterManager_i::CreateEqualTo()
1617 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1618 SMESH::EqualTo_var anObj = aServant->_this();
1619 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
1620 return anObj._retn();
1624 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1626 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1627 SMESH::LogicalNOT_var anObj = aServant->_this();
1628 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
1629 return anObj._retn();
1633 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
1635 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
1636 SMESH::LogicalAND_var anObj = aServant->_this();
1637 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
1638 return anObj._retn();
1642 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
1644 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
1645 SMESH::LogicalOR_var anObj = aServant->_this();
1646 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
1647 return anObj._retn();
1650 Filter_ptr FilterManager_i::CreateFilter()
1652 SMESH::Filter_i* aServant = new SMESH::Filter_i();
1653 SMESH::Filter_var anObj = aServant->_this();
1654 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
1655 return anObj._retn();
1658 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
1660 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
1661 SMESH::FilterLibrary_var anObj = aServant->_this();
1662 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary("<<aFileName<<")";
1663 return anObj._retn();
1666 FilterLibrary_ptr FilterManager_i::CreateLibrary()
1668 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
1669 SMESH::FilterLibrary_var anObj = aServant->_this();
1670 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
1671 return anObj._retn();
1674 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
1676 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
1677 return remove( aFileName ) ? false : true;
1680 //=============================================================================
1682 * SMESH_Gen_i::CreateFilterManager
1684 * Create filter manager
1686 //=============================================================================
1688 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
1690 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1691 SMESH::FilterManager_var anObj = aFilter->_this();
1692 return anObj._retn();
1700 //=======================================================================
1701 // name : Filter_i::Filter_i
1702 // Purpose : Constructor
1703 //=======================================================================
1704 Filter_i::Filter_i()
1705 : myPredicate( NULL )
1708 //=======================================================================
1709 // name : Filter_i::~Filter_i
1710 // Purpose : Destructor
1711 //=======================================================================
1712 Filter_i::~Filter_i()
1715 myPredicate->Destroy();
1717 if(!CORBA::is_nil(myMesh))
1720 TPythonDump()<<this<<".Destroy()";
1723 //=======================================================================
1724 // name : Filter_i::SetPredicate
1725 // Purpose : Set predicate
1726 //=======================================================================
1727 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
1730 myPredicate->Destroy();
1732 myPredicate = SMESH::GetPredicate(thePredicate);
1736 myFilter.SetPredicate( myPredicate->GetPredicate() );
1737 myPredicate->Register();
1738 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1742 //=======================================================================
1743 // name : Filter_i::GetElementType
1744 // Purpose : Get entity type
1745 //=======================================================================
1746 SMESH::ElementType Filter_i::GetElementType()
1748 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
1751 //=======================================================================
1752 // name : Filter_i::SetMesh
1753 // Purpose : Set mesh
1754 //=======================================================================
1757 SetMesh( SMESH_Mesh_ptr theMesh )
1759 if(!CORBA::is_nil(theMesh))
1760 theMesh->Register();
1762 if(!CORBA::is_nil(myMesh))
1766 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
1773 return GetElementsId(myMesh);
1776 //=======================================================================
1777 // name : Filter_i::GetElementsId
1778 // Purpose : Get ids of entities
1779 //=======================================================================
1782 GetElementsId( Predicate_i* thePredicate,
1783 const SMDS_Mesh* theMesh,
1784 Controls::Filter::TIdSequence& theSequence )
1786 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
1791 GetElementsId( Predicate_i* thePredicate,
1792 SMESH_Mesh_ptr theMesh,
1793 Controls::Filter::TIdSequence& theSequence )
1795 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
1796 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
1801 GetElementsId( SMESH_Mesh_ptr theMesh )
1803 SMESH::long_array_var anArray = new SMESH::long_array;
1804 if(!CORBA::is_nil(theMesh)){
1805 Controls::Filter::TIdSequence aSequence;
1806 GetElementsId(myPredicate,theMesh,aSequence);
1807 long i = 0, iEnd = aSequence.size();
1808 anArray->length( iEnd );
1809 for ( ; i < iEnd; i++ )
1810 anArray[ i ] = aSequence[i];
1812 return anArray._retn();
1815 //=======================================================================
1816 // name : getCriteria
1817 // Purpose : Retrieve criterions from predicate
1818 //=======================================================================
1819 static inline bool getCriteria( Predicate_i* thePred,
1820 SMESH::Filter::Criteria_out theCriteria )
1822 int aFType = thePred->GetFunctorType();
1826 case FT_FreeBorders:
1829 CORBA::ULong i = theCriteria->length();
1830 theCriteria->length( i + 1 );
1832 theCriteria[ i ] = createCriterion();
1834 theCriteria[ i ].Type = aFType;
1835 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
1838 case FT_BelongToGeom:
1840 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
1842 CORBA::ULong i = theCriteria->length();
1843 theCriteria->length( i + 1 );
1845 theCriteria[ i ] = createCriterion();
1847 theCriteria[ i ].Type = FT_BelongToGeom;
1848 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1849 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1850 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1854 case FT_BelongToPlane:
1855 case FT_BelongToCylinder:
1857 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
1859 CORBA::ULong i = theCriteria->length();
1860 theCriteria->length( i + 1 );
1862 theCriteria[ i ] = createCriterion();
1864 theCriteria[ i ].Type = aFType;
1865 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1866 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1867 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1868 theCriteria[ i ].Tolerance = aPred->GetTolerance();
1872 case FT_LyingOnGeom:
1874 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
1876 CORBA::ULong i = theCriteria->length();
1877 theCriteria->length( i + 1 );
1879 theCriteria[ i ] = createCriterion();
1881 theCriteria[ i ].Type = FT_LyingOnGeom;
1882 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1883 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1884 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1890 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
1892 CORBA::ULong i = theCriteria->length();
1893 theCriteria->length( i + 1 );
1895 theCriteria[ i ] = createCriterion();
1897 theCriteria[ i ].Type = FT_RangeOfIds;
1898 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
1899 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1903 case FT_BadOrientedVolume:
1905 BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
1907 CORBA::ULong i = theCriteria->length();
1908 theCriteria->length( i + 1 );
1910 theCriteria[ i ] = createCriterion();
1912 theCriteria[ i ].Type = FT_BadOrientedVolume;
1913 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1921 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
1923 CORBA::ULong i = theCriteria->length();
1924 theCriteria->length( i + 1 );
1926 theCriteria[ i ] = createCriterion();
1928 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
1929 theCriteria[ i ].Compare = aFType;
1930 theCriteria[ i ].Threshold = aCompar->GetMargin();
1931 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
1933 if ( aFType == FT_EqualTo )
1935 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
1936 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
1943 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
1944 getCriteria( aPred, theCriteria );
1945 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
1952 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
1953 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
1954 if ( !getCriteria( aPred1, theCriteria ) )
1956 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
1957 return getCriteria( aPred2, theCriteria );
1967 //=======================================================================
1968 // name : Filter_i::GetCriteria
1969 // Purpose : Retrieve criterions from predicate
1970 //=======================================================================
1971 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
1973 theCriteria = new SMESH::Filter::Criteria;
1974 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
1977 //=======================================================================
1978 // name : Filter_i::SetCriteria
1979 // Purpose : Create new predicate and set criterions in it
1980 //=======================================================================
1981 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
1983 if ( myPredicate != 0 )
1984 myPredicate->Destroy();
1986 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1987 FilterManager_ptr aFilterMgr = aFilter->_this();
1989 // CREATE two lists ( PREDICATES and LOG OP )
1992 TPythonDump()<<"aCriteria = []";
1993 std::list<SMESH::Predicate_ptr> aPredicates;
1994 std::list<int> aBinaries;
1995 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
1997 int aCriterion = theCriteria[ i ].Type;
1998 int aCompare = theCriteria[ i ].Compare;
1999 double aThreshold = theCriteria[ i ].Threshold;
2000 int aUnary = theCriteria[ i ].UnaryOp;
2001 int aBinary = theCriteria[ i ].BinaryOp;
2002 double aTolerance = theCriteria[ i ].Tolerance;
2003 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2004 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2005 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
2006 long aPrecision = theCriteria[ i ].Precision;
2008 TPythonDump()<<"aCriteria.append(SMESH.Filter.Criterion("<<
2009 aCriterion<<","<<aCompare<<","<<aThreshold<<",'"<<aThresholdStr<<"',"<<
2010 aUnary<<","<<aBinary<<","<<aTolerance<<","<<aTypeOfElem<<","<<aPrecision<<"))";
2012 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2013 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2015 switch ( aCriterion )
2019 case SMESH::FT_MultiConnection:
2020 aFunctor = aFilterMgr->CreateMultiConnection();
2022 case SMESH::FT_MultiConnection2D:
2023 aFunctor = aFilterMgr->CreateMultiConnection2D();
2025 case SMESH::FT_Length:
2026 aFunctor = aFilterMgr->CreateLength();
2028 case SMESH::FT_Length2D:
2029 aFunctor = aFilterMgr->CreateLength2D();
2031 case SMESH::FT_AspectRatio:
2032 aFunctor = aFilterMgr->CreateAspectRatio();
2034 case SMESH::FT_AspectRatio3D:
2035 aFunctor = aFilterMgr->CreateAspectRatio3D();
2037 case SMESH::FT_Warping:
2038 aFunctor = aFilterMgr->CreateWarping();
2040 case SMESH::FT_MinimumAngle:
2041 aFunctor = aFilterMgr->CreateMinimumAngle();
2043 case SMESH::FT_Taper:
2044 aFunctor = aFilterMgr->CreateTaper();
2046 case SMESH::FT_Skew:
2047 aFunctor = aFilterMgr->CreateSkew();
2049 case SMESH::FT_Area:
2050 aFunctor = aFilterMgr->CreateArea();
2052 case SMESH::FT_Volume3D:
2053 aFunctor = aFilterMgr->CreateVolume3D();
2058 case SMESH::FT_FreeBorders:
2059 aPredicate = aFilterMgr->CreateFreeBorders();
2061 case SMESH::FT_FreeEdges:
2062 aPredicate = aFilterMgr->CreateFreeEdges();
2064 case SMESH::FT_BelongToGeom:
2066 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2067 tmpPred->SetElementType( aTypeOfElem );
2068 tmpPred->SetShape( aThresholdID, aThresholdStr );
2069 aPredicate = tmpPred;
2072 case SMESH::FT_BelongToPlane:
2073 case SMESH::FT_BelongToCylinder:
2075 SMESH::BelongToSurface_ptr tmpPred;
2076 if ( aCriterion == SMESH::FT_BelongToPlane )
2077 tmpPred = aFilterMgr->CreateBelongToPlane();
2079 tmpPred = aFilterMgr->CreateBelongToCylinder();
2080 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2081 tmpPred->SetTolerance( aTolerance );
2082 aPredicate = tmpPred;
2085 case SMESH::FT_LyingOnGeom:
2087 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2088 tmpPred->SetElementType( aTypeOfElem );
2089 tmpPred->SetShape( aThresholdID, aThresholdStr );
2090 aPredicate = tmpPred;
2093 case SMESH::FT_RangeOfIds:
2095 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2096 tmpPred->SetRangeStr( aThresholdStr );
2097 tmpPred->SetElementType( aTypeOfElem );
2098 aPredicate = tmpPred;
2101 case SMESH::FT_BadOrientedVolume:
2103 aPredicate = aFilterMgr->CreateBadOrientedVolume();
2112 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
2114 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
2116 if ( aCompare == SMESH::FT_LessThan )
2117 aComparator = aFilterMgr->CreateLessThan();
2118 else if ( aCompare == SMESH::FT_MoreThan )
2119 aComparator = aFilterMgr->CreateMoreThan();
2120 else if ( aCompare == SMESH::FT_EqualTo )
2121 aComparator = aFilterMgr->CreateEqualTo();
2125 aComparator->SetNumFunctor( aFunctor );
2126 aComparator->SetMargin( aThreshold );
2128 if ( aCompare == FT_EqualTo )
2130 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
2131 anEqualTo->SetTolerance( aTolerance );
2134 aPredicate = aComparator;
2136 aFunctor->SetPrecision( aPrecision );
2140 if ( aUnary == FT_LogicalNOT )
2142 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
2143 aNotPred->SetPredicate( aPredicate );
2144 aPredicate = aNotPred;
2148 aPredicates.push_back( aPredicate );
2149 aBinaries.push_back( aBinary );
2152 TPythonDump()<<this<<".SetCriteria(aCriteria)";
2154 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
2156 // combine all "AND" operations
2158 std::list<SMESH::Predicate_ptr> aResList;
2160 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
2161 std::list<int>::iterator aBinaryIter;
2163 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
2164 int aPrevBinary = SMESH::FT_Undefined;
2166 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
2167 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
2168 ++aPredIter, ++aBinaryIter )
2170 int aCurrBinary = *aBinaryIter;
2172 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
2174 if ( aPrevBinary == SMESH::FT_LogicalAND )
2177 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2178 aBinaryPred->SetPredicate1( aPrevPredicate );
2179 aBinaryPred->SetPredicate2( *aPredIter );
2180 aCurrPred = aBinaryPred;
2183 aCurrPred = *aPredIter;
2185 if ( aCurrBinary != SMESH::FT_LogicalAND )
2186 aResList.push_back( aCurrPred );
2188 aPrevPredicate = aCurrPred;
2189 aPrevBinary = aCurrBinary;
2192 // combine all "OR" operations
2194 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2196 if ( aResList.size() == 1 )
2197 aResPredicate = *aResList.begin();
2198 else if ( aResList.size() > 1 )
2200 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2201 aResPredicate = *anIter;
2203 for ( ; anIter != aResList.end(); ++anIter )
2205 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2206 aBinaryPred->SetPredicate1( aResPredicate );
2207 aBinaryPred->SetPredicate2( *anIter );
2208 aResPredicate = aBinaryPred;
2212 SetPredicate( aResPredicate );
2214 return !aResPredicate->_is_nil();
2217 //=======================================================================
2218 // name : Filter_i::GetPredicate_i
2219 // Purpose : Get implementation of predicate
2220 //=======================================================================
2221 Predicate_i* Filter_i::GetPredicate_i()
2226 //=======================================================================
2227 // name : Filter_i::GetPredicate
2228 // Purpose : Get predicate
2229 //=======================================================================
2230 Predicate_ptr Filter_i::GetPredicate()
2232 if ( myPredicate == 0 )
2233 return SMESH::Predicate::_nil();
2236 SMESH::Predicate_var anObj = myPredicate->_this();
2237 return anObj._retn();
2245 #define ATTR_TYPE "type"
2246 #define ATTR_COMPARE "compare"
2247 #define ATTR_THRESHOLD "threshold"
2248 #define ATTR_UNARY "unary"
2249 #define ATTR_BINARY "binary"
2250 #define ATTR_THRESHOLD_STR "threshold_str"
2251 #define ATTR_TOLERANCE "tolerance"
2252 #define ATTR_ELEMENT_TYPE "ElementType"
2254 //=======================================================================
2256 // Purpose : Convert bool to LDOMString
2257 //=======================================================================
2258 static inline LDOMString toString( const bool val )
2260 return val ? "logical not" : "";
2263 //=======================================================================
2265 // Purpose : Convert LDOMString to bool
2266 //=======================================================================
2267 static inline bool toBool( const LDOMString& theStr )
2269 return theStr.equals( "logical not" );
2272 //=======================================================================
2274 // Purpose : Convert double to LDOMString
2275 //=======================================================================
2276 static inline LDOMString toString( const double val )
2279 sprintf( a, "%e", val );
2280 return LDOMString( a );
2283 //=======================================================================
2285 // Purpose : Convert LDOMString to double
2286 //=======================================================================
2287 static inline double toDouble( const LDOMString& theStr )
2289 return atof( theStr.GetString() );
2292 //=======================================================================
2294 // Purpose : Convert functor type to LDOMString
2295 //=======================================================================
2296 static inline LDOMString toString( const long theType )
2300 case FT_AspectRatio : return "Aspect ratio";
2301 case FT_Warping : return "Warping";
2302 case FT_MinimumAngle : return "Minimum angle";
2303 case FT_Taper : return "Taper";
2304 case FT_Skew : return "Skew";
2305 case FT_Area : return "Area";
2306 case FT_Volume3D : return "Volume3D";
2307 case FT_BelongToGeom : return "Belong to Geom";
2308 case FT_BelongToPlane : return "Belong to Plane";
2309 case FT_BelongToCylinder: return "Belong to Cylinder";
2310 case FT_LyingOnGeom : return "Lying on Geom";
2311 case FT_BadOrientedVolume: return "Bad Oriented Volume";
2312 case FT_RangeOfIds : return "Range of IDs";
2313 case FT_FreeBorders : return "Free borders";
2314 case FT_FreeEdges : return "Free edges";
2315 case FT_MultiConnection : return "Borders at multi-connections";
2316 case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2317 case FT_Length : return "Length";
2318 case FT_Length2D : return "Length2D";
2319 case FT_LessThan : return "Less than";
2320 case FT_MoreThan : return "More than";
2321 case FT_EqualTo : return "Equal to";
2322 case FT_LogicalNOT : return "Not";
2323 case FT_LogicalAND : return "And";
2324 case FT_LogicalOR : return "Or";
2325 case FT_Undefined : return "";
2326 default : return "";
2330 //=======================================================================
2331 // name : toFunctorType
2332 // Purpose : Convert LDOMString to functor type
2333 //=======================================================================
2334 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
2336 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
2337 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
2338 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
2339 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
2340 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
2341 else if ( theStr.equals( "Area" ) ) return FT_Area;
2342 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
2343 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
2344 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
2345 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
2346 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
2347 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
2348 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
2349 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
2350 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
2351 else if ( theStr.equals( "Length" ) ) return FT_Length;
2352 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
2353 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
2354 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
2355 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
2356 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
2357 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
2358 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
2359 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
2360 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
2361 else if ( theStr.equals( "" ) ) return FT_Undefined;
2362 else return FT_Undefined;
2365 //=======================================================================
2366 // name : toFunctorType
2367 // Purpose : Convert LDOMString to value of ElementType enumeration
2368 //=======================================================================
2369 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
2371 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
2372 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
2373 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
2374 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
2375 else return SMESH::ALL;
2378 //=======================================================================
2380 // Purpose : Convert ElementType to string
2381 //=======================================================================
2382 static inline LDOMString toString( const SMESH::ElementType theType )
2386 case SMESH::NODE : return "NODE";
2387 case SMESH::EDGE : return "EDGE";
2388 case SMESH::FACE : return "FACE";
2389 case SMESH::VOLUME : return "VOLUME";
2390 case SMESH::ALL : return "ALL";
2391 default : return "";
2395 //=======================================================================
2396 // name : findFilter
2397 // Purpose : Find filter in document
2398 //=======================================================================
2399 static LDOM_Element findFilter( const char* theFilterName,
2400 const LDOM_Document& theDoc,
2401 LDOM_Node* theParent = 0 )
2403 LDOM_Element aRootElement = theDoc.getDocumentElement();
2404 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
2405 return LDOM_Element();
2407 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
2408 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
2410 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
2411 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2413 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
2414 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
2415 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
2417 if ( theParent != 0 )
2418 *theParent = aTypeNode;
2419 return (LDOM_Element&)aFilter;
2423 return LDOM_Element();
2426 //=======================================================================
2427 // name : getSectionName
2428 // Purpose : Get name of section of filters
2429 //=======================================================================
2430 static const char* getSectionName( const ElementType theType )
2434 case SMESH::NODE : return "Filters for nodes";
2435 case SMESH::EDGE : return "Filters for edges";
2436 case SMESH::FACE : return "Filters for faces";
2437 case SMESH::VOLUME : return "Filters for volumes";
2438 case SMESH::ALL : return "Filters for elements";
2439 default : return "";
2443 //=======================================================================
2444 // name : getSection
2445 // Purpose : Create section for filters corresponding to the entity type
2446 //=======================================================================
2447 static LDOM_Node getSection( const ElementType theType,
2448 LDOM_Document& theDoc,
2449 const bool toCreate = false )
2451 LDOM_Element aRootElement = theDoc.getDocumentElement();
2452 if ( aRootElement.isNull() )
2456 bool anExist = false;
2457 const char* aSectionName = getSectionName( theType );
2458 if ( strcmp( aSectionName, "" ) == 0 )
2461 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
2463 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
2465 aNode = aSections.item( i );
2466 LDOM_Element& anItem = ( LDOM_Element& )aNode;
2467 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
2474 // Create new section if necessary
2479 LDOM_Element aNewItem = theDoc.createElement( "section" );
2480 aNewItem.setAttribute( "name", aSectionName );
2481 aRootElement.appendChild( aNewItem );
2491 //=======================================================================
2492 // name : createFilterItem
2493 // Purpose : Create filter item or LDOM document
2494 //=======================================================================
2495 static LDOM_Element createFilterItem( const char* theName,
2496 SMESH::Filter_ptr theFilter,
2497 LDOM_Document& theDoc )
2499 // create new filter in document
2500 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
2501 aFilterItem.setAttribute( "name", theName );
2503 // save filter criterions
2504 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2506 if ( !theFilter->GetCriteria( aCriteria ) )
2507 return LDOM_Element();
2509 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
2511 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
2513 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type ) );
2514 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
2515 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
2516 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
2517 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
2519 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
2520 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
2521 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
2522 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
2524 aFilterItem.appendChild( aCriterionItem );
2530 //=======================================================================
2531 // name : FilterLibrary_i::FilterLibrary_i
2532 // Purpose : Constructor
2533 //=======================================================================
2534 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
2536 myFileName = strdup( theFileName );
2537 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
2538 myFilterMgr = aFilterMgr->_this();
2542 // Try to use existing library file
2543 bool anExists = false;
2544 if ( !aParser.parse( myFileName ) )
2546 myDoc = aParser.getDocument();
2549 // Create a new XML document if it doesn't exist
2551 myDoc = LDOM_Document::createDocument( LDOMString() );
2553 LDOM_Element aRootElement = myDoc.getDocumentElement();
2554 if ( aRootElement.isNull() )
2556 // If the existing document is empty --> try to create a new one
2558 myDoc = LDOM_Document::createDocument( LDOMString() );
2562 //=======================================================================
2563 // name : FilterLibrary_i::FilterLibrary_i
2564 // Purpose : Constructor
2565 //=======================================================================
2566 FilterLibrary_i::FilterLibrary_i()
2569 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2570 myFilterMgr = aFilter->_this();
2572 myDoc = LDOM_Document::createDocument( LDOMString() );
2575 FilterLibrary_i::~FilterLibrary_i()
2578 TPythonDump()<<this<<".Destroy()";
2581 //=======================================================================
2582 // name : FilterLibrary_i::Copy
2583 // Purpose : Create filter and initialize it with values from library
2584 //=======================================================================
2585 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
2587 Filter_ptr aRes = Filter::_nil();
2588 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
2590 if ( aFilter.isNull() )
2593 std::list<SMESH::Filter::Criterion> aCriteria;
2595 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
2596 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
2598 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
2600 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
2601 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
2602 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
2603 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
2604 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
2606 SMESH::Filter::Criterion aCriterion = createCriterion();
2608 aCriterion.Type = toFunctorType( aTypeStr );
2609 aCriterion.Compare = toFunctorType( aCompareStr );
2610 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
2611 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
2613 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
2615 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
2617 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2618 ? val : atof( str.GetString() );
2620 str = aCrit->getAttribute( ATTR_TOLERANCE );
2621 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2622 ? val : atof( str.GetString() );
2624 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
2625 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
2628 sprintf( a, "%d", val );
2629 aCriterion.ThresholdStr = strdup( a );
2632 aCriterion.ThresholdStr = str.GetString();
2634 aCriteria.push_back( aCriterion );
2637 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
2638 aCriteriaVar->length( aCriteria.size() );
2641 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
2643 for( ; anIter != aCriteria.end(); ++anIter )
2644 aCriteriaVar[ i++ ] = *anIter;
2646 aRes = myFilterMgr->CreateFilter();
2647 aRes->SetCriteria( aCriteriaVar.inout() );
2649 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
2654 //=======================================================================
2655 // name : FilterLibrary_i::SetFileName
2656 // Purpose : Set file name for library
2657 //=======================================================================
2658 void FilterLibrary_i::SetFileName( const char* theFileName )
2661 myFileName = strdup( theFileName );
2662 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
2665 //=======================================================================
2666 // name : FilterLibrary_i::GetFileName
2667 // Purpose : Get file name of library
2668 //=======================================================================
2669 char* FilterLibrary_i::GetFileName()
2671 return CORBA::string_dup( myFileName );
2674 //=======================================================================
2675 // name : FilterLibrary_i::Add
2676 // Purpose : Add new filter to library
2677 //=======================================================================
2678 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
2680 // if filter already in library or entry filter is null do nothing
2681 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2682 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
2685 // get section corresponding to the filter type
2686 ElementType anEntType = theFilter->GetElementType();
2688 LDOM_Node aSection = getSection( anEntType, myDoc, true );
2689 if ( aSection.isNull() )
2692 // create filter item
2693 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
2694 if ( aFilterItem.isNull() )
2698 aSection.appendChild( aFilterItem );
2699 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2700 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
2705 //=======================================================================
2706 // name : FilterLibrary_i::Add
2707 // Purpose : Add new filter to library
2708 //=======================================================================
2709 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
2711 // if filter already in library or entry filter is null do nothing
2712 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2713 if ( !aFilterNode.isNull() )
2716 LDOM_Node aSection = getSection( theType, myDoc, true );
2717 if ( aSection.isNull() )
2720 // create filter item
2721 Filter_var aFilter = myFilterMgr->CreateFilter();
2723 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
2724 if ( aFilterItem.isNull() )
2728 aSection.appendChild( aFilterItem );
2729 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
2734 //=======================================================================
2735 // name : FilterLibrary_i::Delete
2736 // Purpose : Delete filter from library
2737 //=======================================================================
2738 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
2740 LDOM_Node aParentNode;
2741 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
2742 if ( aFilterNode.isNull() || aParentNode.isNull() )
2745 aParentNode.removeChild( aFilterNode );
2746 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
2750 //=======================================================================
2751 // name : FilterLibrary_i::Replace
2752 // Purpose : Replace existing filter with entry filter.
2753 // IMPORTANT : If filter does not exist it is not created
2754 //=======================================================================
2755 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
2756 const char* theNewName,
2757 Filter_ptr theFilter )
2759 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
2760 if ( aFilterItem.isNull() || theFilter->_is_nil() )
2763 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
2764 if ( aNewItem.isNull() )
2768 aFilterItem.ReplaceElement( aNewItem );
2769 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2770 TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
2775 //=======================================================================
2776 // name : FilterLibrary_i::Save
2777 // Purpose : Save library on disk
2778 //=======================================================================
2779 CORBA::Boolean FilterLibrary_i::Save()
2781 if ( myFileName == 0 || strlen( myFileName ) == 0 )
2784 FILE* aOutFile = fopen( myFileName, "wt" );
2788 LDOM_XmlWriter aWriter( aOutFile );
2789 aWriter.SetIndentation( 2 );
2793 TPythonDump()<<this<<".Save()";
2797 //=======================================================================
2798 // name : FilterLibrary_i::SaveAs
2799 // Purpose : Save library on disk
2800 //=======================================================================
2801 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
2803 myFileName = strdup ( aFileName );
2804 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
2808 //=======================================================================
2809 // name : FilterLibrary_i::IsPresent
2810 // Purpose : Verify whether filter is in library
2811 //=======================================================================
2812 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
2814 return !findFilter( theFilterName, myDoc ).isNull();
2817 //=======================================================================
2818 // name : FilterLibrary_i::NbFilters
2819 // Purpose : Return amount of filters in library
2820 //=======================================================================
2821 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
2823 string_array_var aNames = GetNames( theType );
2824 return aNames->length();
2827 //=======================================================================
2828 // name : FilterLibrary_i::GetNames
2829 // Purpose : Get names of filters from library
2830 //=======================================================================
2831 string_array* FilterLibrary_i::GetNames( ElementType theType )
2833 string_array_var anArray = new string_array;
2834 TColStd_SequenceOfHAsciiString aSeq;
2836 LDOM_Node aSection = getSection( theType, myDoc, false );
2838 if ( !aSection.isNull() )
2840 for ( LDOM_Node aFilter = aSection.getFirstChild();
2841 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2843 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
2844 aSeq.Append( new TCollection_HAsciiString(
2845 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
2849 anArray->length( aSeq.Length() );
2850 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
2851 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
2853 return anArray._retn();
2856 //=======================================================================
2857 // name : FilterLibrary_i::GetAllNames
2858 // Purpose : Get names of filters from library
2859 //=======================================================================
2860 string_array* FilterLibrary_i::GetAllNames()
2862 string_array_var aResArray = new string_array;
2863 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
2865 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
2867 int aPrevLength = aResArray->length();
2868 aResArray->length( aPrevLength + aNames->length() );
2869 for ( int i = 0, n = aNames->length(); i < n; i++ )
2870 aResArray[ aPrevLength + i ] = aNames[ i ];
2873 return aResArray._retn();