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.Tolerance = Precision::Confusion();
367 aCriterion.TypeOfElement = SMESH::ALL;
368 aCriterion.Precision = -1;
373 static TopoDS_Shape getShapeByName( const char* theName )
377 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
378 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
379 if (!CORBA::is_nil(aStudy))
381 SALOMEDS::Study::ListOfSObject_var aList =
382 aStudy->FindObjectByName( theName, "GEOM" );
383 if ( aList->length() > 0 )
385 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
386 if ( !aGeomObj->_is_nil() )
388 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
389 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
395 return TopoDS_Shape();
406 Description : An abstact class for all functors
408 Functor_i::Functor_i():
409 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
411 PortableServer::ObjectId_var anObjectId =
412 SMESH_Gen_i::GetPOA()->activate_object( this );
415 Functor_i::~Functor_i()
417 TPythonDump()<<this<<".Destroy()";
420 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
422 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
423 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
426 ElementType Functor_i::GetElementType()
428 return ( ElementType )myFunctorPtr->GetType();
433 Class : NumericalFunctor_i
434 Description : Base class for numerical functors
436 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
438 return myNumericalFunctorPtr->GetValue( theId );
441 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
443 myNumericalFunctorPtr->SetPrecision( thePrecision );
444 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
447 CORBA::Long NumericalFunctor_i::GetPrecision()
449 return myNumericalFunctorPtr->GetPrecision();
452 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
454 return myNumericalFunctorPtr;
459 Class : SMESH_MinimumAngle
460 Description : Functor for calculation of minimum angle
462 MinimumAngle_i::MinimumAngle_i()
464 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
465 myFunctorPtr = myNumericalFunctorPtr;
468 FunctorType MinimumAngle_i::GetFunctorType()
470 return SMESH::FT_MinimumAngle;
476 Description : Functor for calculating aspect ratio
478 AspectRatio_i::AspectRatio_i()
480 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
481 myFunctorPtr = myNumericalFunctorPtr;
484 FunctorType AspectRatio_i::GetFunctorType()
486 return SMESH::FT_AspectRatio;
491 Class : AspectRatio3D
492 Description : Functor for calculating aspect ratio 3D
494 AspectRatio3D_i::AspectRatio3D_i()
496 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
497 myFunctorPtr = myNumericalFunctorPtr;
500 FunctorType AspectRatio3D_i::GetFunctorType()
502 return SMESH::FT_AspectRatio3D;
508 Description : Functor for calculating warping
510 Warping_i::Warping_i()
512 myNumericalFunctorPtr.reset( new Controls::Warping() );
513 myFunctorPtr = myNumericalFunctorPtr;
516 FunctorType Warping_i::GetFunctorType()
518 return SMESH::FT_Warping;
524 Description : Functor for calculating taper
528 myNumericalFunctorPtr.reset( new Controls::Taper() );
529 myFunctorPtr = myNumericalFunctorPtr;
532 FunctorType Taper_i::GetFunctorType()
534 return SMESH::FT_Taper;
540 Description : Functor for calculating skew in degrees
544 myNumericalFunctorPtr.reset( new Controls::Skew() );
545 myFunctorPtr = myNumericalFunctorPtr;
548 FunctorType Skew_i::GetFunctorType()
550 return SMESH::FT_Skew;
555 Description : Functor for calculating area
559 myNumericalFunctorPtr.reset( new Controls::Area() );
560 myFunctorPtr = myNumericalFunctorPtr;
563 FunctorType Area_i::GetFunctorType()
565 return SMESH::FT_Area;
570 Description : Functor for calculating length off edge
574 myNumericalFunctorPtr.reset( new Controls::Length() );
575 myFunctorPtr = myNumericalFunctorPtr;
578 FunctorType Length_i::GetFunctorType()
580 return SMESH::FT_Length;
585 Description : Functor for calculating length of edge
587 Length2D_i::Length2D_i()
589 myNumericalFunctorPtr.reset( new Controls::Length2D() );
590 myFunctorPtr = myNumericalFunctorPtr;
593 FunctorType Length2D_i::GetFunctorType()
595 return SMESH::FT_Length2D;
598 SMESH::Length2D::Values* Length2D_i::GetValues()
600 INFOS("Length2D_i::GetValues");
601 SMESH::Controls::Length2D::TValues aValues;
602 myLength2DPtr->GetValues( aValues );
604 long i = 0, iEnd = aValues.size();
606 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
608 SMESH::Controls::Length2D::TValues::const_iterator anIter;
609 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
611 const SMESH::Controls::Length2D::Value& aVal = *anIter;
612 SMESH::Length2D::Value &aValue = aResult[ i ];
614 aValue.myLength = aVal.myLength;
615 aValue.myPnt1 = aVal.myPntId[ 0 ];
616 aValue.myPnt2 = aVal.myPntId[ 1 ];
619 INFOS("Length2D_i::GetValuess~");
620 return aResult._retn();
624 Class : MultiConnection_i
625 Description : Functor for calculating number of faces conneted to the edge
627 MultiConnection_i::MultiConnection_i()
629 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
630 myFunctorPtr = myNumericalFunctorPtr;
633 FunctorType MultiConnection_i::GetFunctorType()
635 return SMESH::FT_MultiConnection;
639 Class : MultiConnection2D_i
640 Description : Functor for calculating number of faces conneted to the edge
642 MultiConnection2D_i::MultiConnection2D_i()
644 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
645 myFunctorPtr = myNumericalFunctorPtr;
648 FunctorType MultiConnection2D_i::GetFunctorType()
650 return SMESH::FT_MultiConnection2D;
653 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
655 INFOS("MultiConnection2D_i::GetValues");
656 SMESH::Controls::MultiConnection2D::MValues aValues;
657 myMulticonnection2DPtr->GetValues( aValues );
659 long i = 0, iEnd = aValues.size();
661 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
663 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
664 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
666 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
667 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
669 aValue.myPnt1 = aVal.myPntId[ 0 ];
670 aValue.myPnt2 = aVal.myPntId[ 1 ];
671 aValue.myNbConnects = (*anIter).second;
674 INFOS("Multiconnection2D_i::GetValuess~");
675 return aResult._retn();
685 Description : Base class for all predicates
687 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
689 return myPredicatePtr->IsSatisfy( theId );
692 Controls::PredicatePtr Predicate_i::GetPredicate()
694 return myPredicatePtr;
698 Class : BadOrientedVolume_i
699 Description : Verify whether a mesh volume is incorrectly oriented from
700 the point of view of MED convention
702 BadOrientedVolume_i::BadOrientedVolume_i()
704 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
705 myFunctorPtr = myPredicatePtr = control;
708 FunctorType BadOrientedVolume_i::GetFunctorType()
710 return SMESH::FT_BadOrientedVolume;
714 Class : BelongToGeom_i
715 Description : Predicate for selection on geometrical support
717 BelongToGeom_i::BelongToGeom_i()
719 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
720 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
724 BelongToGeom_i::~BelongToGeom_i()
729 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
731 if ( theGeom->_is_nil() )
733 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
734 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
735 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
736 myBelongToGeomPtr->SetGeom( aLocShape );
737 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
740 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
742 myBelongToGeomPtr->SetGeom( theShape );
745 void BelongToGeom_i::SetElementType(ElementType theType){
746 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
747 TPythonDump()<<this<<".SetElementType("<<theType<<")";
750 FunctorType BelongToGeom_i::GetFunctorType()
752 return SMESH::FT_BelongToGeom;
755 void BelongToGeom_i::SetShapeName( const char* theName )
758 myShapeName = strdup( theName );
759 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
760 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
763 char* BelongToGeom_i::GetShapeName()
765 return CORBA::string_dup( myShapeName );
769 Class : BelongToSurface_i
770 Description : Predicate for selection on geometrical support
772 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
774 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
775 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
777 mySurfaceType = theSurfaceType;
780 BelongToSurface_i::~BelongToSurface_i()
785 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
787 if ( theGeom->_is_nil() )
789 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
790 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
791 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
793 if ( aLocShape.ShapeType() == TopAbs_FACE )
795 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
796 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
798 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
803 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
804 TPythonDump()<<this<<".SetSurface("<<theGeom<<",'"<<theType<<"')";
807 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
810 myShapeName = strdup( theName );
811 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
812 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
815 char* BelongToSurface_i::GetShapeName()
817 return CORBA::string_dup( myShapeName );
820 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
822 myElementsOnSurfacePtr->SetTolerance( theToler );
823 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
826 CORBA::Double BelongToSurface_i::GetTolerance()
828 return myElementsOnSurfacePtr->GetTolerance();
832 Class : BelongToPlane_i
833 Description : Verify whether mesh element lie in pointed Geom planar object
836 BelongToPlane_i::BelongToPlane_i()
837 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
841 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
843 BelongToSurface_i::SetSurface( theGeom, theType );
844 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
847 FunctorType BelongToPlane_i::GetFunctorType()
849 return FT_BelongToPlane;
853 Class : BelongToCylinder_i
854 Description : Verify whether mesh element lie in pointed Geom planar object
857 BelongToCylinder_i::BelongToCylinder_i()
858 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
862 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
864 BelongToSurface_i::SetSurface( theGeom, theType );
865 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
868 FunctorType BelongToCylinder_i::GetFunctorType()
870 return FT_BelongToCylinder;
874 Class : LyingOnGeom_i
875 Description : Predicate for selection on geometrical support
877 LyingOnGeom_i::LyingOnGeom_i()
879 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
880 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
884 LyingOnGeom_i::~LyingOnGeom_i()
889 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
891 if ( theGeom->_is_nil() )
893 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
894 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
895 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
896 myLyingOnGeomPtr->SetGeom( aLocShape );
897 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
900 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
902 myLyingOnGeomPtr->SetGeom( theShape );
905 void LyingOnGeom_i::SetElementType(ElementType theType){
906 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
907 TPythonDump()<<this<<".SetElementType("<<theType<<")";
910 FunctorType LyingOnGeom_i::GetFunctorType()
912 return SMESH::FT_LyingOnGeom;
915 void LyingOnGeom_i::SetShapeName( const char* theName )
918 myShapeName = strdup( theName );
919 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
920 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
923 char* LyingOnGeom_i::GetShapeName()
925 return CORBA::string_dup( myShapeName );
929 Class : FreeBorders_i
930 Description : Predicate for free borders
932 FreeBorders_i::FreeBorders_i()
934 myPredicatePtr.reset(new Controls::FreeBorders());
935 myFunctorPtr = myPredicatePtr;
938 FunctorType FreeBorders_i::GetFunctorType()
940 return SMESH::FT_FreeBorders;
945 Description : Predicate for free borders
947 FreeEdges_i::FreeEdges_i()
948 : myFreeEdgesPtr( new Controls::FreeEdges() )
950 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
953 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
955 INFOS("FreeEdges_i::GetBorders");
956 SMESH::Controls::FreeEdges::TBorders aBorders;
957 myFreeEdgesPtr->GetBoreders( aBorders );
959 long i = 0, iEnd = aBorders.size();
961 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders(iEnd);
963 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
964 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
966 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
967 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
969 aBorder.myElemId = aBord.myElemId;
970 aBorder.myPnt1 = aBord.myPntId[ 0 ];
971 aBorder.myPnt2 = aBord.myPntId[ 1 ];
974 INFOS("FreeEdges_i::GetBorders~");
975 return aResult._retn();
978 FunctorType FreeEdges_i::GetFunctorType()
980 return SMESH::FT_FreeEdges;
985 Description : Predicate for Range of Ids.
986 Range may be specified with two ways.
987 1. Using AddToRange method
988 2. With SetRangeStr method. Parameter of this method is a string
989 like as "1,2,3,50-60,63,67,70-"
992 RangeOfIds_i::RangeOfIds_i()
994 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
995 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
998 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1000 CORBA::Long iEnd = theIds.length();
1001 for ( CORBA::Long i = 0; i < iEnd; i++ )
1002 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1003 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1006 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1008 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1009 return myRangeOfIdsPtr->SetRangeStr(
1010 TCollection_AsciiString( (Standard_CString)theRange ) );
1013 char* RangeOfIds_i::GetRangeStr()
1015 TCollection_AsciiString aStr;
1016 myRangeOfIdsPtr->GetRangeStr( aStr );
1017 return CORBA::string_dup( aStr.ToCString() );
1020 void RangeOfIds_i::SetElementType( ElementType theType )
1022 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1023 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1026 FunctorType RangeOfIds_i::GetFunctorType()
1028 return SMESH::FT_RangeOfIds;
1032 Class : Comparator_i
1033 Description : Base class for comparators
1035 Comparator_i::Comparator_i():
1036 myNumericalFunctor( NULL )
1039 Comparator_i::~Comparator_i()
1041 if ( myNumericalFunctor )
1042 myNumericalFunctor->Destroy();
1045 void Comparator_i::SetMargin( CORBA::Double theValue )
1047 myComparatorPtr->SetMargin( theValue );
1048 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1051 CORBA::Double Comparator_i::GetMargin()
1053 return myComparatorPtr->GetMargin();
1056 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1058 if ( myNumericalFunctor )
1059 myNumericalFunctor->Destroy();
1061 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1063 if ( myNumericalFunctor )
1065 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1066 myNumericalFunctor->Register();
1067 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1071 Controls::ComparatorPtr Comparator_i::GetComparator()
1073 return myComparatorPtr;
1076 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1078 return myNumericalFunctor;
1084 Description : Comparator "<"
1086 LessThan_i::LessThan_i()
1088 myComparatorPtr.reset( new Controls::LessThan() );
1089 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1092 FunctorType LessThan_i::GetFunctorType()
1094 return SMESH::FT_LessThan;
1100 Description : Comparator ">"
1102 MoreThan_i::MoreThan_i()
1104 myComparatorPtr.reset( new Controls::MoreThan() );
1105 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1108 FunctorType MoreThan_i::GetFunctorType()
1110 return SMESH::FT_MoreThan;
1116 Description : Comparator "="
1118 EqualTo_i::EqualTo_i()
1119 : myEqualToPtr( new Controls::EqualTo() )
1121 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1124 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1126 myEqualToPtr->SetTolerance( theToler );
1127 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1130 CORBA::Double EqualTo_i::GetTolerance()
1132 return myEqualToPtr->GetTolerance();
1135 FunctorType EqualTo_i::GetFunctorType()
1137 return SMESH::FT_EqualTo;
1141 Class : LogicalNOT_i
1142 Description : Logical NOT predicate
1144 LogicalNOT_i::LogicalNOT_i()
1145 : myPredicate( NULL ),
1146 myLogicalNOTPtr( new Controls::LogicalNOT() )
1148 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1151 LogicalNOT_i::~LogicalNOT_i()
1154 myPredicate->Destroy();
1157 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1160 myPredicate->Destroy();
1162 myPredicate = SMESH::GetPredicate(thePredicate);
1165 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1166 myPredicate->Register();
1167 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1171 FunctorType LogicalNOT_i::GetFunctorType()
1173 return SMESH::FT_LogicalNOT;
1176 Predicate_i* LogicalNOT_i::GetPredicate_i()
1183 Class : LogicalBinary_i
1184 Description : Base class for binary logical predicate
1186 LogicalBinary_i::LogicalBinary_i()
1187 : myPredicate1( NULL ),
1188 myPredicate2( NULL )
1191 LogicalBinary_i::~LogicalBinary_i()
1194 myPredicate1->Destroy();
1197 myPredicate2->Destroy();
1200 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1203 myPredicate1->SetMesh( theMesh );
1206 myPredicate2->SetMesh( theMesh );
1209 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1212 myPredicate1->Destroy();
1214 myPredicate1 = SMESH::GetPredicate(thePredicate);
1216 if ( myPredicate1 ){
1217 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1218 myPredicate1->Register();
1219 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1223 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1226 myPredicate2->Destroy();
1228 myPredicate2 = SMESH::GetPredicate(thePredicate);
1230 if ( myPredicate2 ){
1231 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1232 myPredicate2->Register();
1233 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1237 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1239 return myLogicalBinaryPtr;
1242 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1244 return myPredicate1;
1246 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1248 return myPredicate2;
1253 Class : LogicalAND_i
1254 Description : Logical AND
1256 LogicalAND_i::LogicalAND_i()
1258 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1259 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1262 FunctorType LogicalAND_i::GetFunctorType()
1264 return SMESH::FT_LogicalAND;
1270 Description : Logical OR
1272 LogicalOR_i::LogicalOR_i()
1274 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1275 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1278 FunctorType LogicalOR_i::GetFunctorType()
1280 return SMESH::FT_LogicalOR;
1288 FilterManager_i::FilterManager_i()
1289 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1291 PortableServer::ObjectId_var anObjectId =
1292 SMESH_Gen_i::GetPOA()->activate_object( this );
1296 FilterManager_i::~FilterManager_i()
1298 TPythonDump()<<this<<".Destroy()";
1302 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1304 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1305 SMESH::MinimumAngle_var anObj = aServant->_this();
1306 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1307 return anObj._retn();
1311 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1313 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1314 SMESH::AspectRatio_var anObj = aServant->_this();
1315 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1316 return anObj._retn();
1320 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1322 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1323 SMESH::AspectRatio3D_var anObj = aServant->_this();
1324 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1325 return anObj._retn();
1329 Warping_ptr FilterManager_i::CreateWarping()
1331 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1332 SMESH::Warping_var anObj = aServant->_this();
1333 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1334 return anObj._retn();
1338 Taper_ptr FilterManager_i::CreateTaper()
1340 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1341 SMESH::Taper_var anObj = aServant->_this();
1342 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1343 return anObj._retn();
1347 Skew_ptr FilterManager_i::CreateSkew()
1349 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1350 SMESH::Skew_var anObj = aServant->_this();
1351 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1352 return anObj._retn();
1356 Area_ptr FilterManager_i::CreateArea()
1358 SMESH::Area_i* aServant = new SMESH::Area_i();
1359 SMESH::Area_var anObj = aServant->_this();
1360 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1361 return anObj._retn();
1365 Length_ptr FilterManager_i::CreateLength()
1367 SMESH::Length_i* aServant = new SMESH::Length_i();
1368 SMESH::Length_var anObj = aServant->_this();
1369 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1370 return anObj._retn();
1373 Length2D_ptr FilterManager_i::CreateLength2D()
1375 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1376 SMESH::Length2D_var anObj = aServant->_this();
1377 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1378 return anObj._retn();
1381 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1383 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1384 SMESH::MultiConnection_var anObj = aServant->_this();
1385 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1386 return anObj._retn();
1389 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1391 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1392 SMESH::MultiConnection2D_var anObj = aServant->_this();
1393 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
1394 return anObj._retn();
1397 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1399 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1400 SMESH::BelongToGeom_var anObj = aServant->_this();
1401 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
1402 return anObj._retn();
1405 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1407 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1408 SMESH::BelongToPlane_var anObj = aServant->_this();
1409 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
1410 return anObj._retn();
1413 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1415 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1416 SMESH::BelongToCylinder_var anObj = aServant->_this();
1417 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
1418 return anObj._retn();
1421 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
1423 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
1424 SMESH::LyingOnGeom_var anObj = aServant->_this();
1425 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
1426 return anObj._retn();
1429 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1431 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1432 SMESH::FreeBorders_var anObj = aServant->_this();
1433 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
1434 return anObj._retn();
1437 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1439 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1440 SMESH::FreeEdges_var anObj = aServant->_this();
1441 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
1442 return anObj._retn();
1445 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1447 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1448 SMESH::RangeOfIds_var anObj = aServant->_this();
1449 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
1450 return anObj._retn();
1453 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
1455 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
1456 SMESH::BadOrientedVolume_var anObj = aServant->_this();
1457 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
1458 return anObj._retn();
1461 LessThan_ptr FilterManager_i::CreateLessThan()
1463 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1464 SMESH::LessThan_var anObj = aServant->_this();
1465 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
1466 return anObj._retn();
1470 MoreThan_ptr FilterManager_i::CreateMoreThan()
1472 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1473 SMESH::MoreThan_var anObj = aServant->_this();
1474 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
1475 return anObj._retn();
1478 EqualTo_ptr FilterManager_i::CreateEqualTo()
1480 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1481 SMESH::EqualTo_var anObj = aServant->_this();
1482 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
1483 return anObj._retn();
1487 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1489 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1490 SMESH::LogicalNOT_var anObj = aServant->_this();
1491 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
1492 return anObj._retn();
1496 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
1498 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
1499 SMESH::LogicalAND_var anObj = aServant->_this();
1500 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
1501 return anObj._retn();
1505 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
1507 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
1508 SMESH::LogicalOR_var anObj = aServant->_this();
1509 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
1510 return anObj._retn();
1513 Filter_ptr FilterManager_i::CreateFilter()
1515 SMESH::Filter_i* aServant = new SMESH::Filter_i();
1516 SMESH::Filter_var anObj = aServant->_this();
1517 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
1518 return anObj._retn();
1521 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
1523 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
1524 SMESH::FilterLibrary_var anObj = aServant->_this();
1525 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary("<<aFileName<<")";
1526 return anObj._retn();
1529 FilterLibrary_ptr FilterManager_i::CreateLibrary()
1531 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
1532 SMESH::FilterLibrary_var anObj = aServant->_this();
1533 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
1534 return anObj._retn();
1537 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
1539 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
1540 return remove( aFileName ) ? false : true;
1543 //=============================================================================
1545 * SMESH_Gen_i::CreateFilterManager
1547 * Create filter manager
1549 //=============================================================================
1551 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
1553 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1554 SMESH::FilterManager_var anObj = aFilter->_this();
1555 return anObj._retn();
1563 //=======================================================================
1564 // name : Filter_i::Filter_i
1565 // Purpose : Constructor
1566 //=======================================================================
1567 Filter_i::Filter_i()
1568 : myPredicate( NULL )
1571 //=======================================================================
1572 // name : Filter_i::~Filter_i
1573 // Purpose : Destructor
1574 //=======================================================================
1575 Filter_i::~Filter_i()
1578 myPredicate->Destroy();
1580 if(!CORBA::is_nil(myMesh))
1583 TPythonDump()<<this<<".Destroy()";
1586 //=======================================================================
1587 // name : Filter_i::SetPredicate
1588 // Purpose : Set predicate
1589 //=======================================================================
1590 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
1593 myPredicate->Destroy();
1595 myPredicate = SMESH::GetPredicate(thePredicate);
1599 myFilter.SetPredicate( myPredicate->GetPredicate() );
1600 myPredicate->Register();
1601 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1605 //=======================================================================
1606 // name : Filter_i::GetElementType
1607 // Purpose : Get entity type
1608 //=======================================================================
1609 SMESH::ElementType Filter_i::GetElementType()
1611 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
1614 //=======================================================================
1615 // name : Filter_i::SetMesh
1616 // Purpose : Set mesh
1617 //=======================================================================
1620 SetMesh( SMESH_Mesh_ptr theMesh )
1622 if(!CORBA::is_nil(theMesh))
1623 theMesh->Register();
1625 if(!CORBA::is_nil(myMesh))
1629 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
1636 return GetElementsId(myMesh);
1639 //=======================================================================
1640 // name : Filter_i::GetElementsId
1641 // Purpose : Get ids of entities
1642 //=======================================================================
1645 GetElementsId( Predicate_i* thePredicate,
1646 const SMDS_Mesh* theMesh,
1647 Controls::Filter::TIdSequence& theSequence )
1649 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
1654 GetElementsId( Predicate_i* thePredicate,
1655 SMESH_Mesh_ptr theMesh,
1656 Controls::Filter::TIdSequence& theSequence )
1658 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
1659 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
1664 GetElementsId( SMESH_Mesh_ptr theMesh )
1666 SMESH::long_array_var anArray = new SMESH::long_array;
1667 if(!CORBA::is_nil(theMesh)){
1668 Controls::Filter::TIdSequence aSequence;
1669 GetElementsId(myPredicate,theMesh,aSequence);
1670 long i = 0, iEnd = aSequence.size();
1671 anArray->length( iEnd );
1672 for ( ; i < iEnd; i++ )
1673 anArray[ i ] = aSequence[i];
1675 return anArray._retn();
1678 //=======================================================================
1679 // name : getCriteria
1680 // Purpose : Retrieve criterions from predicate
1681 //=======================================================================
1682 static inline bool getCriteria( Predicate_i* thePred,
1683 SMESH::Filter::Criteria_out theCriteria )
1685 int aFType = thePred->GetFunctorType();
1689 case FT_FreeBorders:
1692 CORBA::ULong i = theCriteria->length();
1693 theCriteria->length( i + 1 );
1695 theCriteria[ i ] = createCriterion();
1697 theCriteria[ i ].Type = aFType;
1698 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
1701 case FT_BelongToGeom:
1703 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
1705 CORBA::ULong i = theCriteria->length();
1706 theCriteria->length( i + 1 );
1708 theCriteria[ i ] = createCriterion();
1710 theCriteria[ i ].Type = FT_BelongToGeom;
1711 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1712 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1716 case FT_BelongToPlane:
1717 case FT_BelongToCylinder:
1719 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
1721 CORBA::ULong i = theCriteria->length();
1722 theCriteria->length( i + 1 );
1724 theCriteria[ i ] = createCriterion();
1726 theCriteria[ i ].Type = aFType;
1727 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1728 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1729 theCriteria[ i ].Tolerance = aPred->GetTolerance();
1733 case FT_LyingOnGeom:
1735 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
1737 CORBA::ULong i = theCriteria->length();
1738 theCriteria->length( i + 1 );
1740 theCriteria[ i ] = createCriterion();
1742 theCriteria[ i ].Type = FT_LyingOnGeom;
1743 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1744 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1750 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
1752 CORBA::ULong i = theCriteria->length();
1753 theCriteria->length( i + 1 );
1755 theCriteria[ i ] = createCriterion();
1757 theCriteria[ i ].Type = FT_RangeOfIds;
1758 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
1759 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1763 case FT_BadOrientedVolume:
1765 BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
1767 CORBA::ULong i = theCriteria->length();
1768 theCriteria->length( i + 1 );
1770 theCriteria[ i ] = createCriterion();
1772 theCriteria[ i ].Type = FT_BadOrientedVolume;
1773 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1781 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
1783 CORBA::ULong i = theCriteria->length();
1784 theCriteria->length( i + 1 );
1786 theCriteria[ i ] = createCriterion();
1788 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
1789 theCriteria[ i ].Compare = aFType;
1790 theCriteria[ i ].Threshold = aCompar->GetMargin();
1791 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
1793 if ( aFType == FT_EqualTo )
1795 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
1796 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
1803 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
1804 getCriteria( aPred, theCriteria );
1805 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
1812 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
1813 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
1814 if ( !getCriteria( aPred1, theCriteria ) )
1816 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
1817 return getCriteria( aPred2, theCriteria );
1827 //=======================================================================
1828 // name : Filter_i::GetCriteria
1829 // Purpose : Retrieve criterions from predicate
1830 //=======================================================================
1831 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
1833 theCriteria = new SMESH::Filter::Criteria;
1834 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
1837 //=======================================================================
1838 // name : Filter_i::SetCriteria
1839 // Purpose : Create new predicate and set criterions in it
1840 //=======================================================================
1841 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
1843 if ( myPredicate != 0 )
1844 myPredicate->Destroy();
1846 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1847 FilterManager_ptr aFilterMgr = aFilter->_this();
1849 // CREATE two lists ( PREDICATES and LOG OP )
1852 TPythonDump()<<"aCriteria = []";
1853 std::list<SMESH::Predicate_ptr> aPredicates;
1854 std::list<int> aBinaries;
1855 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
1857 int aCriterion = theCriteria[ i ].Type;
1858 int aCompare = theCriteria[ i ].Compare;
1859 double aThreshold = theCriteria[ i ].Threshold;
1860 int aUnary = theCriteria[ i ].UnaryOp;
1861 int aBinary = theCriteria[ i ].BinaryOp;
1862 double aTolerance = theCriteria[ i ].Tolerance;
1863 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
1864 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
1865 long aPrecision = theCriteria[ i ].Precision;
1867 TPythonDump()<<"aCriteria.append(SMESH.Filter.Criterion("<<
1868 aCriterion<<","<<aCompare<<","<<aThreshold<<",'"<<aThresholdStr<<"',"<<
1869 aUnary<<","<<aBinary<<","<<aTolerance<<","<<aTypeOfElem<<","<<aPrecision<<"))";
1871 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
1872 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
1874 switch ( aCriterion )
1878 case SMESH::FT_MultiConnection:
1879 aFunctor = aFilterMgr->CreateMultiConnection();
1881 case SMESH::FT_MultiConnection2D:
1882 aFunctor = aFilterMgr->CreateMultiConnection2D();
1884 case SMESH::FT_Length:
1885 aFunctor = aFilterMgr->CreateLength();
1887 case SMESH::FT_Length2D:
1888 aFunctor = aFilterMgr->CreateLength2D();
1890 case SMESH::FT_AspectRatio:
1891 aFunctor = aFilterMgr->CreateAspectRatio();
1893 case SMESH::FT_AspectRatio3D:
1894 aFunctor = aFilterMgr->CreateAspectRatio3D();
1896 case SMESH::FT_Warping:
1897 aFunctor = aFilterMgr->CreateWarping();
1899 case SMESH::FT_MinimumAngle:
1900 aFunctor = aFilterMgr->CreateMinimumAngle();
1902 case SMESH::FT_Taper:
1903 aFunctor = aFilterMgr->CreateTaper();
1905 case SMESH::FT_Skew:
1906 aFunctor = aFilterMgr->CreateSkew();
1908 case SMESH::FT_Area:
1909 aFunctor = aFilterMgr->CreateArea();
1914 case SMESH::FT_FreeBorders:
1915 aPredicate = aFilterMgr->CreateFreeBorders();
1917 case SMESH::FT_FreeEdges:
1918 aPredicate = aFilterMgr->CreateFreeEdges();
1920 case SMESH::FT_BelongToGeom:
1922 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
1923 tmpPred->SetElementType( aTypeOfElem );
1924 tmpPred->SetShapeName( aThresholdStr );
1925 aPredicate = tmpPred;
1928 case SMESH::FT_BelongToPlane:
1929 case SMESH::FT_BelongToCylinder:
1931 SMESH::BelongToSurface_ptr tmpPred;
1932 if ( aCriterion == SMESH::FT_BelongToPlane )
1933 tmpPred = aFilterMgr->CreateBelongToPlane();
1935 tmpPred = aFilterMgr->CreateBelongToCylinder();
1936 tmpPred->SetShapeName( aThresholdStr, aTypeOfElem );
1937 tmpPred->SetTolerance( aTolerance );
1938 aPredicate = tmpPred;
1941 case SMESH::FT_LyingOnGeom:
1943 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
1944 tmpPred->SetElementType( aTypeOfElem );
1945 tmpPred->SetShapeName( aThresholdStr );
1946 aPredicate = tmpPred;
1949 case SMESH::FT_RangeOfIds:
1951 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
1952 tmpPred->SetRangeStr( aThresholdStr );
1953 tmpPred->SetElementType( aTypeOfElem );
1954 aPredicate = tmpPred;
1957 case SMESH::FT_BadOrientedVolume:
1959 aPredicate = aFilterMgr->CreateBadOrientedVolume();
1968 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
1970 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
1972 if ( aCompare == SMESH::FT_LessThan )
1973 aComparator = aFilterMgr->CreateLessThan();
1974 else if ( aCompare == SMESH::FT_MoreThan )
1975 aComparator = aFilterMgr->CreateMoreThan();
1976 else if ( aCompare == SMESH::FT_EqualTo )
1977 aComparator = aFilterMgr->CreateEqualTo();
1981 aComparator->SetNumFunctor( aFunctor );
1982 aComparator->SetMargin( aThreshold );
1984 if ( aCompare == FT_EqualTo )
1986 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
1987 anEqualTo->SetTolerance( aTolerance );
1990 aPredicate = aComparator;
1992 aFunctor->SetPrecision( aPrecision );
1996 if ( aUnary == FT_LogicalNOT )
1998 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
1999 aNotPred->SetPredicate( aPredicate );
2000 aPredicate = aNotPred;
2004 aPredicates.push_back( aPredicate );
2005 aBinaries.push_back( aBinary );
2008 TPythonDump()<<this<<".SetCriteria(aCriteria)";
2010 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
2012 // combine all "AND" operations
2014 std::list<SMESH::Predicate_ptr> aResList;
2016 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
2017 std::list<int>::iterator aBinaryIter;
2019 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
2020 int aPrevBinary = SMESH::FT_Undefined;
2022 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
2023 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
2024 ++aPredIter, ++aBinaryIter )
2026 int aCurrBinary = *aBinaryIter;
2028 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
2030 if ( aPrevBinary == SMESH::FT_LogicalAND )
2033 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2034 aBinaryPred->SetPredicate1( aPrevPredicate );
2035 aBinaryPred->SetPredicate2( *aPredIter );
2036 aCurrPred = aBinaryPred;
2039 aCurrPred = *aPredIter;
2041 if ( aCurrBinary != SMESH::FT_LogicalAND )
2042 aResList.push_back( aCurrPred );
2044 aPrevPredicate = aCurrPred;
2045 aPrevBinary = aCurrBinary;
2048 // combine all "OR" operations
2050 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2052 if ( aResList.size() == 1 )
2053 aResPredicate = *aResList.begin();
2054 else if ( aResList.size() > 1 )
2056 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2057 aResPredicate = *anIter;
2059 for ( ; anIter != aResList.end(); ++anIter )
2061 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2062 aBinaryPred->SetPredicate1( aResPredicate );
2063 aBinaryPred->SetPredicate2( *anIter );
2064 aResPredicate = aBinaryPred;
2068 SetPredicate( aResPredicate );
2070 return !aResPredicate->_is_nil();
2073 //=======================================================================
2074 // name : Filter_i::GetPredicate_i
2075 // Purpose : Get implementation of predicate
2076 //=======================================================================
2077 Predicate_i* Filter_i::GetPredicate_i()
2082 //=======================================================================
2083 // name : Filter_i::GetPredicate
2084 // Purpose : Get predicate
2085 //=======================================================================
2086 Predicate_ptr Filter_i::GetPredicate()
2088 if ( myPredicate == 0 )
2089 return SMESH::Predicate::_nil();
2092 SMESH::Predicate_var anObj = myPredicate->_this();
2093 return anObj._retn();
2101 #define ATTR_TYPE "type"
2102 #define ATTR_COMPARE "compare"
2103 #define ATTR_THRESHOLD "threshold"
2104 #define ATTR_UNARY "unary"
2105 #define ATTR_BINARY "binary"
2106 #define ATTR_THRESHOLD_STR "threshold_str"
2107 #define ATTR_TOLERANCE "tolerance"
2108 #define ATTR_ELEMENT_TYPE "ElementType"
2110 //=======================================================================
2112 // Purpose : Convert bool to LDOMString
2113 //=======================================================================
2114 static inline LDOMString toString( const bool val )
2116 return val ? "logical not" : "";
2119 //=======================================================================
2121 // Purpose : Convert LDOMString to bool
2122 //=======================================================================
2123 static inline bool toBool( const LDOMString& theStr )
2125 return theStr.equals( "logical not" );
2128 //=======================================================================
2130 // Purpose : Convert double to LDOMString
2131 //=======================================================================
2132 static inline LDOMString toString( const double val )
2135 sprintf( a, "%e", val );
2136 return LDOMString( a );
2139 //=======================================================================
2141 // Purpose : Convert LDOMString to double
2142 //=======================================================================
2143 static inline double toDouble( const LDOMString& theStr )
2145 return atof( theStr.GetString() );
2148 //=======================================================================
2150 // Purpose : Convert functor type to LDOMString
2151 //=======================================================================
2152 static inline LDOMString toString( const long theType )
2156 case FT_AspectRatio : return "Aspect ratio";
2157 case FT_Warping : return "Warping";
2158 case FT_MinimumAngle : return "Minimum angle";
2159 case FT_Taper : return "Taper";
2160 case FT_Skew : return "Skew";
2161 case FT_Area : return "Area";
2162 case FT_BelongToGeom : return "Belong to Geom";
2163 case FT_BelongToPlane : return "Belong to Plane";
2164 case FT_BelongToCylinder: return "Belong to Cylinder";
2165 case FT_LyingOnGeom : return "Lying on Geom";
2166 case FT_BadOrientedVolume: return "Bad Oriented Volume";
2167 case FT_RangeOfIds : return "Range of IDs";
2168 case FT_FreeBorders : return "Free borders";
2169 case FT_FreeEdges : return "Free edges";
2170 case FT_MultiConnection : return "Borders at multi-connections";
2171 case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2172 case FT_Length : return "Length";
2173 case FT_Length2D : return "Length2D";
2174 case FT_LessThan : return "Less than";
2175 case FT_MoreThan : return "More than";
2176 case FT_EqualTo : return "Equal to";
2177 case FT_LogicalNOT : return "Not";
2178 case FT_LogicalAND : return "And";
2179 case FT_LogicalOR : return "Or";
2180 case FT_Undefined : return "";
2181 default : return "";
2185 //=======================================================================
2186 // name : toFunctorType
2187 // Purpose : Convert LDOMString to functor type
2188 //=======================================================================
2189 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
2191 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
2192 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
2193 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
2194 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
2195 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
2196 else if ( theStr.equals( "Area" ) ) return FT_Area;
2197 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
2198 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
2199 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
2200 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
2201 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
2202 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
2203 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
2204 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
2205 else if ( theStr.equals( "Length" ) ) return FT_Length;
2206 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
2207 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
2208 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
2209 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
2210 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
2211 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
2212 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
2213 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
2214 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
2215 else if ( theStr.equals( "" ) ) return FT_Undefined;
2216 else return FT_Undefined;
2219 //=======================================================================
2220 // name : toFunctorType
2221 // Purpose : Convert LDOMString to value of ElementType enumeration
2222 //=======================================================================
2223 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
2225 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
2226 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
2227 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
2228 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
2229 else return SMESH::ALL;
2232 //=======================================================================
2234 // Purpose : Convert ElementType to string
2235 //=======================================================================
2236 static inline LDOMString toString( const SMESH::ElementType theType )
2240 case SMESH::NODE : return "NODE";
2241 case SMESH::EDGE : return "EDGE";
2242 case SMESH::FACE : return "FACE";
2243 case SMESH::VOLUME : return "VOLUME";
2244 case SMESH::ALL : return "ALL";
2245 default : return "";
2249 //=======================================================================
2250 // name : findFilter
2251 // Purpose : Find filter in document
2252 //=======================================================================
2253 static LDOM_Element findFilter( const char* theFilterName,
2254 const LDOM_Document& theDoc,
2255 LDOM_Node* theParent = 0 )
2257 LDOM_Element aRootElement = theDoc.getDocumentElement();
2258 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
2259 return LDOM_Element();
2261 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
2262 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
2264 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
2265 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2267 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
2268 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
2269 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
2271 if ( theParent != 0 )
2272 *theParent = aTypeNode;
2273 return (LDOM_Element&)aFilter;
2277 return LDOM_Element();
2280 //=======================================================================
2281 // name : getSectionName
2282 // Purpose : Get name of section of filters
2283 //=======================================================================
2284 static const char* getSectionName( const ElementType theType )
2288 case SMESH::NODE : return "Filters for nodes";
2289 case SMESH::EDGE : return "Filters for edges";
2290 case SMESH::FACE : return "Filters for faces";
2291 case SMESH::VOLUME : return "Filters for volumes";
2292 case SMESH::ALL : return "Filters for elements";
2293 default : return "";
2297 //=======================================================================
2298 // name : getSection
2299 // Purpose : Create section for filters corresponding to the entity type
2300 //=======================================================================
2301 static LDOM_Node getSection( const ElementType theType,
2302 LDOM_Document& theDoc,
2303 const bool toCreate = false )
2305 LDOM_Element aRootElement = theDoc.getDocumentElement();
2306 if ( aRootElement.isNull() )
2310 bool anExist = false;
2311 const char* aSectionName = getSectionName( theType );
2312 if ( strcmp( aSectionName, "" ) == 0 )
2315 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
2317 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
2319 aNode = aSections.item( i );
2320 LDOM_Element& anItem = ( LDOM_Element& )aNode;
2321 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
2328 // Create new section if necessary
2333 LDOM_Element aNewItem = theDoc.createElement( "section" );
2334 aNewItem.setAttribute( "name", aSectionName );
2335 aRootElement.appendChild( aNewItem );
2345 //=======================================================================
2346 // name : createFilterItem
2347 // Purpose : Create filter item or LDOM document
2348 //=======================================================================
2349 static LDOM_Element createFilterItem( const char* theName,
2350 SMESH::Filter_ptr theFilter,
2351 LDOM_Document& theDoc )
2353 // create new filter in document
2354 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
2355 aFilterItem.setAttribute( "name", theName );
2357 // save filter criterions
2358 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2360 if ( !theFilter->GetCriteria( aCriteria ) )
2361 return LDOM_Element();
2363 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
2365 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
2367 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type ) );
2368 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
2369 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
2370 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
2371 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
2373 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
2374 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
2375 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
2376 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
2378 aFilterItem.appendChild( aCriterionItem );
2384 //=======================================================================
2385 // name : FilterLibrary_i::FilterLibrary_i
2386 // Purpose : Constructor
2387 //=======================================================================
2388 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
2390 myFileName = strdup( theFileName );
2391 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
2392 myFilterMgr = aFilterMgr->_this();
2396 // Try to use existing library file
2397 bool anExists = false;
2398 if ( !aParser.parse( myFileName ) )
2400 myDoc = aParser.getDocument();
2403 // Create a new XML document if it doesn't exist
2405 myDoc = LDOM_Document::createDocument( LDOMString() );
2407 LDOM_Element aRootElement = myDoc.getDocumentElement();
2408 if ( aRootElement.isNull() )
2410 // If the existing document is empty --> try to create a new one
2412 myDoc = LDOM_Document::createDocument( LDOMString() );
2416 //=======================================================================
2417 // name : FilterLibrary_i::FilterLibrary_i
2418 // Purpose : Constructor
2419 //=======================================================================
2420 FilterLibrary_i::FilterLibrary_i()
2423 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2424 myFilterMgr = aFilter->_this();
2426 myDoc = LDOM_Document::createDocument( LDOMString() );
2429 FilterLibrary_i::~FilterLibrary_i()
2432 TPythonDump()<<this<<".Destroy()";
2435 //=======================================================================
2436 // name : FilterLibrary_i::Copy
2437 // Purpose : Create filter and initialize it with values from library
2438 //=======================================================================
2439 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
2441 Filter_ptr aRes = Filter::_nil();
2442 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
2444 if ( aFilter.isNull() )
2447 std::list<SMESH::Filter::Criterion> aCriteria;
2449 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
2450 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
2452 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
2454 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
2455 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
2456 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
2457 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
2458 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
2460 SMESH::Filter::Criterion aCriterion = createCriterion();
2462 aCriterion.Type = toFunctorType( aTypeStr );
2463 aCriterion.Compare = toFunctorType( aCompareStr );
2464 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
2465 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
2467 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
2469 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
2471 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2472 ? val : atof( str.GetString() );
2474 str = aCrit->getAttribute( ATTR_TOLERANCE );
2475 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2476 ? val : atof( str.GetString() );
2478 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
2479 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
2482 sprintf( a, "%d", val );
2483 aCriterion.ThresholdStr = strdup( a );
2486 aCriterion.ThresholdStr = str.GetString();
2488 aCriteria.push_back( aCriterion );
2491 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
2492 aCriteriaVar->length( aCriteria.size() );
2495 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
2497 for( ; anIter != aCriteria.end(); ++anIter )
2498 aCriteriaVar[ i++ ] = *anIter;
2500 aRes = myFilterMgr->CreateFilter();
2501 aRes->SetCriteria( aCriteriaVar.inout() );
2503 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
2508 //=======================================================================
2509 // name : FilterLibrary_i::SetFileName
2510 // Purpose : Set file name for library
2511 //=======================================================================
2512 void FilterLibrary_i::SetFileName( const char* theFileName )
2515 myFileName = strdup( theFileName );
2516 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
2519 //=======================================================================
2520 // name : FilterLibrary_i::GetFileName
2521 // Purpose : Get file name of library
2522 //=======================================================================
2523 char* FilterLibrary_i::GetFileName()
2525 return CORBA::string_dup( myFileName );
2528 //=======================================================================
2529 // name : FilterLibrary_i::Add
2530 // Purpose : Add new filter to library
2531 //=======================================================================
2532 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
2534 // if filter already in library or entry filter is null do nothing
2535 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2536 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
2539 // get section corresponding to the filter type
2540 ElementType anEntType = theFilter->GetElementType();
2542 LDOM_Node aSection = getSection( anEntType, myDoc, true );
2543 if ( aSection.isNull() )
2546 // create filter item
2547 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
2548 if ( aFilterItem.isNull() )
2552 aSection.appendChild( aFilterItem );
2553 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2554 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
2559 //=======================================================================
2560 // name : FilterLibrary_i::Add
2561 // Purpose : Add new filter to library
2562 //=======================================================================
2563 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
2565 // if filter already in library or entry filter is null do nothing
2566 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2567 if ( !aFilterNode.isNull() )
2570 LDOM_Node aSection = getSection( theType, myDoc, true );
2571 if ( aSection.isNull() )
2574 // create filter item
2575 Filter_var aFilter = myFilterMgr->CreateFilter();
2577 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
2578 if ( aFilterItem.isNull() )
2582 aSection.appendChild( aFilterItem );
2583 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
2588 //=======================================================================
2589 // name : FilterLibrary_i::Delete
2590 // Purpose : Delete filter from library
2591 //=======================================================================
2592 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
2594 LDOM_Node aParentNode;
2595 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
2596 if ( aFilterNode.isNull() || aParentNode.isNull() )
2599 aParentNode.removeChild( aFilterNode );
2600 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
2604 //=======================================================================
2605 // name : FilterLibrary_i::Replace
2606 // Purpose : Replace existing filter with entry filter.
2607 // IMPORTANT : If filter does not exist it is not created
2608 //=======================================================================
2609 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
2610 const char* theNewName,
2611 Filter_ptr theFilter )
2613 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
2614 if ( aFilterItem.isNull() || theFilter->_is_nil() )
2617 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
2618 if ( aNewItem.isNull() )
2622 aFilterItem.ReplaceElement( aNewItem );
2623 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2624 TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
2629 //=======================================================================
2630 // name : FilterLibrary_i::Save
2631 // Purpose : Save library on disk
2632 //=======================================================================
2633 CORBA::Boolean FilterLibrary_i::Save()
2635 if ( myFileName == 0 || strlen( myFileName ) == 0 )
2638 FILE* aOutFile = fopen( myFileName, "wt" );
2642 LDOM_XmlWriter aWriter( aOutFile );
2643 aWriter.SetIndentation( 2 );
2647 TPythonDump()<<this<<".Save()";
2651 //=======================================================================
2652 // name : FilterLibrary_i::SaveAs
2653 // Purpose : Save library on disk
2654 //=======================================================================
2655 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
2657 myFileName = strdup ( aFileName );
2658 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
2662 //=======================================================================
2663 // name : FilterLibrary_i::IsPresent
2664 // Purpose : Verify whether filter is in library
2665 //=======================================================================
2666 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
2668 return !findFilter( theFilterName, myDoc ).isNull();
2671 //=======================================================================
2672 // name : FilterLibrary_i::NbFilters
2673 // Purpose : Return amount of filters in library
2674 //=======================================================================
2675 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
2677 string_array_var aNames = GetNames( theType );
2678 return aNames->length();
2681 //=======================================================================
2682 // name : FilterLibrary_i::GetNames
2683 // Purpose : Get names of filters from library
2684 //=======================================================================
2685 string_array* FilterLibrary_i::GetNames( ElementType theType )
2687 string_array_var anArray = new string_array;
2688 TColStd_SequenceOfHAsciiString aSeq;
2690 LDOM_Node aSection = getSection( theType, myDoc, false );
2692 if ( !aSection.isNull() )
2694 for ( LDOM_Node aFilter = aSection.getFirstChild();
2695 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2697 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
2698 aSeq.Append( new TCollection_HAsciiString(
2699 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
2703 anArray->length( aSeq.Length() );
2704 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
2705 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
2707 return anArray._retn();
2710 //=======================================================================
2711 // name : FilterLibrary_i::GetAllNames
2712 // Purpose : Get names of filters from library
2713 //=======================================================================
2714 string_array* FilterLibrary_i::GetAllNames()
2716 string_array_var aResArray = new string_array;
2717 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
2719 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
2721 int aPrevLength = aResArray->length();
2722 aResArray->length( aPrevLength + aNames->length() );
2723 for ( int i = 0, n = aNames->length(); i < n; i++ )
2724 aResArray[ aPrevLength + i ] = aNames[ i ];
2727 return aResArray._retn();