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"
33 #include "SMDS_Mesh.hxx"
34 #include "SMDS_MeshNode.hxx"
35 #include "SMDS_MeshElement.hxx"
37 #include "SMESHDS_Mesh.hxx"
39 #include <LDOM_Document.hxx>
40 #include <LDOM_Element.hxx>
41 #include <LDOM_Node.hxx>
42 #include <LDOMString.hxx>
43 #include <LDOMParser.hxx>
44 #include <LDOM_XmlWriter.hxx>
45 #include <TCollection_HAsciiString.hxx>
46 #include <TColStd_ListIteratorOfListOfInteger.hxx>
47 #include <TColStd_ListOfInteger.hxx>
48 #include <TColStd_ListOfReal.hxx>
49 #include <TColStd_MapOfInteger.hxx>
50 #include <TColStd_SequenceOfHAsciiString.hxx>
51 #include <TColStd_ListIteratorOfListOfReal.hxx>
52 #include <Precision.hxx>
53 #include <BRep_Tool.hxx>
54 #include <TopoDS_Shape.hxx>
56 #include <TopoDS_Face.hxx>
57 #include <Geom_Plane.hxx>
58 #include <Geom_CylindricalSurface.hxx>
59 #include <TopExp_Explorer.hxx>
60 #include <OSD_Path.hxx>
61 #include <OSD_File.hxx>
63 using namespace SMESH;
64 using namespace SMESH::Controls;
68 Description : Predicate for verifying whether entiy belong to
69 specified geometrical support
72 Controls::BelongToGeom::BelongToGeom()
77 void Controls::BelongToGeom::SetMesh( SMDS_Mesh* theMesh )
79 myMeshDS = dynamic_cast<SMESHDS_Mesh*>(theMesh);
82 void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
87 static bool IsContains( SMESHDS_Mesh* theMeshDS,
88 const TopoDS_Shape& theShape,
89 const SMDS_MeshElement* theElem,
90 TopAbs_ShapeEnum theFindShapeEnum,
91 TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE )
93 TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
97 const TopoDS_Shape& aShape = anExp.Current();
98 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
99 if( aSubMesh->Contains( theElem ) )
107 bool Controls::BelongToGeom::IsSatisfy( long theId )
109 if ( myMeshDS == 0 || myShape.IsNull() )
112 if( myType == SMDSAbs_Node )
114 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
116 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
117 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
118 switch( aTypeOfPosition )
120 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
121 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
122 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
123 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
129 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
131 if( myType == SMDSAbs_All )
133 return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
134 IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
135 IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
136 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
138 else if( myType == anElem->GetType() )
142 case SMDSAbs_Edge : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
143 case SMDSAbs_Face : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
144 case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
145 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
154 void Controls::BelongToGeom::SetType( SMDSAbs_ElementType theType )
159 SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
164 TopoDS_Shape Controls::BelongToGeom::GetShape()
169 SMESHDS_Mesh* Controls::BelongToGeom::GetMeshDS()
179 static inline SMDS_Mesh* MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
181 SMESH_Mesh_i* anImplPtr =
182 dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( theMesh ).in() );
183 return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
186 static inline SMESH::long_array* toArray( const TColStd_ListOfInteger& aList )
188 SMESH::long_array_var anArray = new SMESH::long_array;
189 anArray->length( aList.Extent() );
190 TColStd_ListIteratorOfListOfInteger anIter( aList );
192 for( ; anIter.More(); anIter.Next() )
193 anArray[ i++ ] = anIter.Value();
195 return anArray._retn();
198 static inline SMESH::double_array* toArray( const TColStd_ListOfReal& aList )
200 SMESH::double_array_var anArray = new SMESH::double_array;
201 anArray->length( aList.Extent() );
202 TColStd_ListIteratorOfListOfReal anIter( aList );
204 for( ; anIter.More(); anIter.Next() )
205 anArray[ i++ ] = anIter.Value();
207 return anArray._retn();
210 static SMESH::Filter::Criterion createCriterion()
212 SMESH::Filter::Criterion aCriterion;
214 aCriterion.Type = FT_Undefined;
215 aCriterion.Compare = FT_Undefined;
216 aCriterion.Threshold = 0;
217 aCriterion.UnaryOp = FT_Undefined;
218 aCriterion.BinaryOp = FT_Undefined;
219 aCriterion.ThresholdStr = "";
220 aCriterion.Tolerance = Precision::Confusion();
221 aCriterion.TypeOfElement = SMESH::ALL;
222 aCriterion.Precision = -1;
227 static TopoDS_Shape getShapeByName( const char* theName )
231 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
232 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
235 SALOMEDS::Study::ListOfSObject_var aList =
236 aStudy->FindObjectByName( theName, "GEOM" );
237 if ( aList->length() > 0 )
239 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
240 if ( !aGeomObj->_is_nil() )
242 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
243 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
249 return TopoDS_Shape();
260 Description : An abstact class for all functors
262 Functor_i::Functor_i():
263 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
265 SMESH_Gen_i::GetPOA()->activate_object( this );
268 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
270 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
271 INFOS("Functor_i::SetMesh~");
274 ElementType Functor_i::GetElementType()
276 return ( ElementType )myFunctorPtr->GetType();
281 Class : NumericalFunctor_i
282 Description : Base class for numerical functors
284 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
286 return myNumericalFunctorPtr->GetValue( theId );
289 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
291 myNumericalFunctorPtr->SetPrecision( thePrecision );
294 CORBA::Long NumericalFunctor_i::GetPrecision()
296 return myNumericalFunctorPtr->GetPrecision();
299 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
301 return myNumericalFunctorPtr;
306 Class : SMESH_MinimumAngle
307 Description : Functor for calculation of minimum angle
309 MinimumAngle_i::MinimumAngle_i()
311 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
312 myFunctorPtr = myNumericalFunctorPtr;
315 FunctorType MinimumAngle_i::GetFunctorType()
317 return SMESH::FT_MinimumAngle;
323 Description : Functor for calculating aspect ratio
325 AspectRatio_i::AspectRatio_i()
327 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
328 myFunctorPtr = myNumericalFunctorPtr;
331 FunctorType AspectRatio_i::GetFunctorType()
333 return SMESH::FT_AspectRatio;
338 Class : AspectRatio3D
339 Description : Functor for calculating aspect ratio 3D
341 AspectRatio3D_i::AspectRatio3D_i()
343 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
344 myFunctorPtr = myNumericalFunctorPtr;
347 FunctorType AspectRatio3D_i::GetFunctorType()
349 return SMESH::FT_AspectRatio3D;
355 Description : Functor for calculating warping
357 Warping_i::Warping_i()
359 myNumericalFunctorPtr.reset( new Controls::Warping() );
360 myFunctorPtr = myNumericalFunctorPtr;
363 FunctorType Warping_i::GetFunctorType()
365 return SMESH::FT_Warping;
371 Description : Functor for calculating taper
375 myNumericalFunctorPtr.reset( new Controls::Taper() );
376 myFunctorPtr = myNumericalFunctorPtr;
379 FunctorType Taper_i::GetFunctorType()
381 return SMESH::FT_Taper;
387 Description : Functor for calculating skew in degrees
391 myNumericalFunctorPtr.reset( new Controls::Skew() );
392 myFunctorPtr = myNumericalFunctorPtr;
395 FunctorType Skew_i::GetFunctorType()
397 return SMESH::FT_Skew;
402 Description : Functor for calculating area
406 myNumericalFunctorPtr.reset( new Controls::Area() );
407 myFunctorPtr = myNumericalFunctorPtr;
410 FunctorType Area_i::GetFunctorType()
412 return SMESH::FT_Area;
417 Description : Functor for calculating length off edge
421 myNumericalFunctorPtr.reset( new Controls::Length() );
422 myFunctorPtr = myNumericalFunctorPtr;
425 FunctorType Length_i::GetFunctorType()
427 return SMESH::FT_Length;
432 Description : Functor for calculating length of edge
434 Length2D_i::Length2D_i()
436 myNumericalFunctorPtr.reset( new Controls::Length2D() );
437 myFunctorPtr = myNumericalFunctorPtr;
440 FunctorType Length2D_i::GetFunctorType()
442 return SMESH::FT_Length2D;
445 SMESH::Length2D::Values* Length2D_i::GetValues()
447 INFOS("Length2D_i::GetValues");
448 SMESH::Controls::Length2D::TValues aValues;
449 myLength2DPtr->GetValues( aValues );
451 long i = 0, iEnd = aValues.size();
453 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
455 SMESH::Controls::Length2D::TValues::const_iterator anIter;
456 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
458 const SMESH::Controls::Length2D::Value& aVal = *anIter;
459 SMESH::Length2D::Value &aValue = aResult[ i ];
461 aValue.myLength = aVal.myLength;
462 aValue.myPnt1 = aVal.myPntId[ 0 ];
463 aValue.myPnt2 = aVal.myPntId[ 1 ];
467 INFOS("Length2D_i::GetValuess~");
468 return aResult._retn();
472 Class : MultiConnection_i
473 Description : Functor for calculating number of faces conneted to the edge
475 MultiConnection_i::MultiConnection_i()
477 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
478 myFunctorPtr = myNumericalFunctorPtr;
481 FunctorType MultiConnection_i::GetFunctorType()
483 return SMESH::FT_MultiConnection;
487 Class : MultiConnection2D_i
488 Description : Functor for calculating number of faces conneted to the edge
490 MultiConnection2D_i::MultiConnection2D_i()
492 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
493 myFunctorPtr = myNumericalFunctorPtr;
496 FunctorType MultiConnection2D_i::GetFunctorType()
498 return SMESH::FT_MultiConnection2D;
501 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
503 INFOS("MultiConnection2D_i::GetValues");
504 SMESH::Controls::MultiConnection2D::MValues aValues;
505 myMulticonnection2DPtr->GetValues( aValues );
507 long i = 0, iEnd = aValues.size();
509 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
511 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
512 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
514 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
515 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
517 aValue.myPnt1 = aVal.myPntId[ 0 ];
518 aValue.myPnt2 = aVal.myPntId[ 1 ];
519 aValue.myNbConnects = (*anIter).second;
523 INFOS("Multiconnection2D_i::GetValuess~");
524 return aResult._retn();
534 Description : Base class for all predicates
536 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
538 return myPredicatePtr->IsSatisfy( theId );
541 Controls::PredicatePtr Predicate_i::GetPredicate()
543 return myPredicatePtr;
548 Class : BelongToGeom_i
549 Description : Predicate for selection on geometrical support
551 BelongToGeom_i::BelongToGeom_i()
553 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
554 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
558 BelongToGeom_i::~BelongToGeom_i()
563 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
565 if ( theGeom->_is_nil() )
567 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
568 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
569 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
570 myBelongToGeomPtr->SetGeom( aLocShape );
573 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
575 myBelongToGeomPtr->SetGeom( theShape );
578 void BelongToGeom_i::SetElementType(ElementType theType){
579 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
582 FunctorType BelongToGeom_i::GetFunctorType()
584 return SMESH::FT_BelongToGeom;
587 void BelongToGeom_i::SetShapeName( const char* theName )
590 myShapeName = strdup( theName );
591 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
594 char* BelongToGeom_i::GetShapeName()
596 return CORBA::string_dup( myShapeName );
600 Class : BelongToSurface_i
601 Description : Predicate for selection on geometrical support
603 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
605 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
606 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
608 mySurfaceType = theSurfaceType;
611 BelongToSurface_i::~BelongToSurface_i()
616 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
618 if ( theGeom->_is_nil() )
620 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
621 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
622 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
624 if ( aLocShape.ShapeType() == TopAbs_FACE )
626 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
627 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
629 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
634 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
637 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
640 myShapeName = strdup( theName );
641 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
644 char* BelongToSurface_i::GetShapeName()
646 return CORBA::string_dup( myShapeName );
649 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
651 myElementsOnSurfacePtr->SetTolerance( theToler );
654 CORBA::Double BelongToSurface_i::GetTolerance()
656 return myElementsOnSurfacePtr->GetTolerance();
660 Class : BelongToPlane_i
661 Description : Verify whether mesh element lie in pointed Geom planar object
664 BelongToPlane_i::BelongToPlane_i()
665 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
669 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
671 BelongToSurface_i::SetSurface( theGeom, theType );
674 FunctorType BelongToPlane_i::GetFunctorType()
676 return FT_BelongToPlane;
680 Class : BelongToCylinder_i
681 Description : Verify whether mesh element lie in pointed Geom planar object
684 BelongToCylinder_i::BelongToCylinder_i()
685 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
689 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
691 BelongToSurface_i::SetSurface( theGeom, theType );
694 FunctorType BelongToCylinder_i::GetFunctorType()
696 return FT_BelongToCylinder;
702 Class : FreeBorders_i
703 Description : Predicate for free borders
705 FreeBorders_i::FreeBorders_i()
707 myPredicatePtr.reset(new Controls::FreeBorders());
708 myFunctorPtr = myPredicatePtr;
711 FunctorType FreeBorders_i::GetFunctorType()
713 return SMESH::FT_FreeBorders;
718 Description : Predicate for free borders
720 FreeEdges_i::FreeEdges_i()
721 : myFreeEdgesPtr( new Controls::FreeEdges() )
723 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
726 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
728 INFOS("FreeEdges_i::GetBorders");
729 SMESH::Controls::FreeEdges::TBorders aBorders;
730 myFreeEdgesPtr->GetBoreders( aBorders );
732 long i = 0, iEnd = aBorders.size();
734 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders(iEnd);
736 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
737 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
739 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
740 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
742 aBorder.myElemId = aBord.myElemId;
743 aBorder.myPnt1 = aBord.myPntId[ 0 ];
744 aBorder.myPnt2 = aBord.myPntId[ 1 ];
747 INFOS("FreeEdges_i::GetBorders~");
748 return aResult._retn();
751 FunctorType FreeEdges_i::GetFunctorType()
753 return SMESH::FT_FreeEdges;
758 Description : Predicate for Range of Ids.
759 Range may be specified with two ways.
760 1. Using AddToRange method
761 2. With SetRangeStr method. Parameter of this method is a string
762 like as "1,2,3,50-60,63,67,70-"
765 RangeOfIds_i::RangeOfIds_i()
767 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
768 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
771 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
773 CORBA::Long iEnd = theIds.length();
774 for ( CORBA::Long i = 0; i < iEnd; i++ )
775 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
778 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
780 return myRangeOfIdsPtr->SetRangeStr(
781 TCollection_AsciiString( (Standard_CString)theRange ) );
784 char* RangeOfIds_i::GetRangeStr()
786 TCollection_AsciiString aStr;
787 myRangeOfIdsPtr->GetRangeStr( aStr );
788 return CORBA::string_dup( aStr.ToCString() );
791 void RangeOfIds_i::SetElementType( ElementType theType )
793 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
796 FunctorType RangeOfIds_i::GetFunctorType()
798 return SMESH::FT_RangeOfIds;
803 Description : Base class for comparators
805 Comparator_i::Comparator_i():
806 myNumericalFunctor( NULL )
809 Comparator_i::~Comparator_i()
811 if ( myNumericalFunctor )
812 myNumericalFunctor->Destroy();
815 void Comparator_i::SetMargin( CORBA::Double theValue )
817 myComparatorPtr->SetMargin( theValue );
820 CORBA::Double Comparator_i::GetMargin()
822 return myComparatorPtr->GetMargin();
825 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
827 if ( myNumericalFunctor )
828 myNumericalFunctor->Destroy();
830 myNumericalFunctor = dynamic_cast<NumericalFunctor_i*>( SMESH_Gen_i::GetServant( theFunct ).in() );
832 if ( myNumericalFunctor )
834 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
835 myNumericalFunctor->Register();
839 Controls::ComparatorPtr Comparator_i::GetComparator()
841 return myComparatorPtr;
844 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
846 return myNumericalFunctor;
852 Description : Comparator "<"
854 LessThan_i::LessThan_i()
856 myComparatorPtr.reset( new Controls::LessThan() );
857 myFunctorPtr = myPredicatePtr = myComparatorPtr;
860 FunctorType LessThan_i::GetFunctorType()
862 return SMESH::FT_LessThan;
868 Description : Comparator ">"
870 MoreThan_i::MoreThan_i()
872 myComparatorPtr.reset( new Controls::MoreThan() );
873 myFunctorPtr = myPredicatePtr = myComparatorPtr;
876 FunctorType MoreThan_i::GetFunctorType()
878 return SMESH::FT_MoreThan;
884 Description : Comparator "="
886 EqualTo_i::EqualTo_i()
887 : myEqualToPtr( new Controls::EqualTo() )
889 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
892 void EqualTo_i::SetTolerance( CORBA::Double theToler )
894 myEqualToPtr->SetTolerance( theToler );
897 CORBA::Double EqualTo_i::GetTolerance()
899 return myEqualToPtr->GetTolerance();
902 FunctorType EqualTo_i::GetFunctorType()
904 return SMESH::FT_EqualTo;
909 Description : Logical NOT predicate
911 LogicalNOT_i::LogicalNOT_i()
912 : myPredicate( NULL ),
913 myLogicalNOTPtr( new Controls::LogicalNOT() )
915 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
918 LogicalNOT_i::~LogicalNOT_i()
921 myPredicate->Destroy();
924 void LogicalNOT_i::SetPredicate( Predicate_ptr thePred )
927 myPredicate->Destroy();
929 myPredicate = dynamic_cast<Predicate_i*>( SMESH_Gen_i::GetServant( thePred ).in() );
932 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
933 myPredicate->Register();
937 FunctorType LogicalNOT_i::GetFunctorType()
939 return SMESH::FT_LogicalNOT;
942 Predicate_i* LogicalNOT_i::GetPredicate_i()
949 Class : LogicalBinary_i
950 Description : Base class for binary logical predicate
952 LogicalBinary_i::LogicalBinary_i()
953 : myPredicate1( NULL ),
957 LogicalBinary_i::~LogicalBinary_i()
960 myPredicate1->Destroy();
963 myPredicate2->Destroy();
966 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
969 myPredicate1->SetMesh( theMesh );
972 myPredicate2->SetMesh( theMesh );
975 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
978 myPredicate1->Destroy();
980 myPredicate1 = dynamic_cast<Predicate_i*>( SMESH_Gen_i::GetServant( thePredicate ).in() );
983 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
984 myPredicate1->Register();
988 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
991 myPredicate2->Destroy();
993 myPredicate2 = dynamic_cast<Predicate_i*>( SMESH_Gen_i::GetServant( thePredicate ).in() );
996 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
997 myPredicate2->Register();
1001 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1003 return myLogicalBinaryPtr;
1006 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1008 return myPredicate1;
1010 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1012 return myPredicate2;
1017 Class : LogicalAND_i
1018 Description : Logical AND
1020 LogicalAND_i::LogicalAND_i()
1022 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1023 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1026 FunctorType LogicalAND_i::GetFunctorType()
1028 return SMESH::FT_LogicalAND;
1034 Description : Logical OR
1036 LogicalOR_i::LogicalOR_i()
1038 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1039 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1042 FunctorType LogicalOR_i::GetFunctorType()
1044 return SMESH::FT_LogicalOR;
1052 FilterManager_i::FilterManager_i()
1053 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1055 SMESH_Gen_i::GetPOA()->activate_object( this );
1058 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1060 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1061 SMESH::MinimumAngle_var anObj = aServant->_this();
1062 return anObj._retn();
1066 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1068 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1069 SMESH::AspectRatio_var anObj = aServant->_this();
1070 return anObj._retn();
1074 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1076 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1077 SMESH::AspectRatio3D_var anObj = aServant->_this();
1078 return anObj._retn();
1082 Warping_ptr FilterManager_i::CreateWarping()
1084 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1085 SMESH::Warping_var anObj = aServant->_this();
1086 return anObj._retn();
1090 Taper_ptr FilterManager_i::CreateTaper()
1092 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1093 SMESH::Taper_var anObj = aServant->_this();
1094 return anObj._retn();
1098 Skew_ptr FilterManager_i::CreateSkew()
1100 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1101 SMESH::Skew_var anObj = aServant->_this();
1102 return anObj._retn();
1106 Area_ptr FilterManager_i::CreateArea()
1108 SMESH::Area_i* aServant = new SMESH::Area_i();
1109 SMESH::Area_var anObj = aServant->_this();
1110 return anObj._retn();
1114 Length_ptr FilterManager_i::CreateLength()
1116 SMESH::Length_i* aServant = new SMESH::Length_i();
1117 SMESH::Length_var anObj = aServant->_this();
1118 return anObj._retn();
1121 Length2D_ptr FilterManager_i::CreateLength2D()
1123 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1124 SMESH::Length2D_var anObj = aServant->_this();
1125 return anObj._retn();
1128 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1130 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1131 SMESH::MultiConnection_var anObj = aServant->_this();
1132 return anObj._retn();
1135 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1137 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1138 SMESH::MultiConnection2D_var anObj = aServant->_this();
1139 return anObj._retn();
1142 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1144 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1145 SMESH::BelongToGeom_var anObj = aServant->_this();
1146 return anObj._retn();
1149 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1151 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1152 SMESH::BelongToPlane_var anObj = aServant->_this();
1153 return anObj._retn();
1156 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1158 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1159 SMESH::BelongToCylinder_var anObj = aServant->_this();
1160 return anObj._retn();
1163 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1165 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1166 SMESH::FreeBorders_var anObj = aServant->_this();
1167 return anObj._retn();
1170 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1172 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1173 SMESH::FreeEdges_var anObj = aServant->_this();
1174 return anObj._retn();
1177 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1179 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1180 SMESH::RangeOfIds_var anObj = aServant->_this();
1181 return anObj._retn();
1184 LessThan_ptr FilterManager_i::CreateLessThan()
1186 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1187 SMESH::LessThan_var anObj = aServant->_this();
1188 return anObj._retn();
1192 MoreThan_ptr FilterManager_i::CreateMoreThan()
1194 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1195 SMESH::MoreThan_var anObj = aServant->_this();
1196 return anObj._retn();
1199 EqualTo_ptr FilterManager_i::CreateEqualTo()
1201 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1202 SMESH::EqualTo_var anObj = aServant->_this();
1203 return anObj._retn();
1207 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1209 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1210 SMESH::LogicalNOT_var anObj = aServant->_this();
1211 return anObj._retn();
1215 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
1217 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
1218 SMESH::LogicalAND_var anObj = aServant->_this();
1219 return anObj._retn();
1223 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
1225 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
1226 SMESH::LogicalOR_var anObj = aServant->_this();
1227 return anObj._retn();
1230 Filter_ptr FilterManager_i::CreateFilter()
1232 SMESH::Filter_i* aServant = new SMESH::Filter_i();
1233 SMESH::Filter_var anObj = aServant->_this();
1234 return anObj._retn();
1237 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
1239 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
1240 SMESH::FilterLibrary_var anObj = aServant->_this();
1241 return anObj._retn();
1244 FilterLibrary_ptr FilterManager_i::CreateLibrary()
1246 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
1247 SMESH::FilterLibrary_var anObj = aServant->_this();
1248 return anObj._retn();
1251 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
1253 return remove( aFileName ) ? false : true;
1256 //=============================================================================
1258 * SMESH_Gen_i::CreateFilterManager
1260 * Create filter manager
1262 //=============================================================================
1264 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
1266 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1267 SMESH::FilterManager_var anObj = aFilter->_this();
1268 return anObj._retn();
1276 //=======================================================================
1277 // name : Filter_i::Filter_i
1278 // Purpose : Constructor
1279 //=======================================================================
1280 Filter_i::Filter_i()
1281 : myPredicate( NULL )
1284 //=======================================================================
1285 // name : Filter_i::~Filter_i
1286 // Purpose : Destructor
1287 //=======================================================================
1288 Filter_i::~Filter_i()
1291 myPredicate->Destroy();
1294 //=======================================================================
1295 // name : Filter_i::SetPredicate
1296 // Purpose : Set predicate
1297 //=======================================================================
1298 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
1301 myPredicate->Destroy();
1303 myPredicate = dynamic_cast<Predicate_i*>( SMESH_Gen_i::GetServant( thePredicate ).in() );
1307 myFilter.SetPredicate( myPredicate->GetPredicate() );
1308 myPredicate->Register();
1312 //=======================================================================
1313 // name : Filter_i::GetElementType
1314 // Purpose : Get entity type
1315 //=======================================================================
1316 SMESH::ElementType Filter_i::GetElementType()
1318 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
1321 //=======================================================================
1322 // name : Filter_i::SetMesh
1323 // Purpose : Set mesh
1324 //=======================================================================
1325 void Filter_i::SetMesh( SMESH_Mesh_ptr theMesh )
1328 myPredicate->SetMesh( theMesh );
1331 //=======================================================================
1332 // name : Filter_i::GetElementsId
1333 // Purpose : Get ids of entities
1334 //=======================================================================
1335 SMESH::long_array* Filter_i::GetElementsId( SMESH_Mesh_ptr theMesh )
1337 SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh);
1338 Controls::Filter::TIdSequence aSequence = myFilter.GetElementsId(aMesh);
1340 SMESH::long_array_var anArray = new SMESH::long_array;
1341 long i = 0, iEnd = aSequence.size();
1343 anArray->length( iEnd );
1344 for ( ; i < iEnd; i++ )
1345 anArray[ i ] = aSequence[i];
1347 return anArray._retn();
1350 //=======================================================================
1351 // name : getCriteria
1352 // Purpose : Retrieve criterions from predicate
1353 //=======================================================================
1354 static inline bool getCriteria( Predicate_i* thePred,
1355 SMESH::Filter::Criteria_out theCriteria )
1357 int aFType = thePred->GetFunctorType();
1361 case FT_FreeBorders:
1364 CORBA::ULong i = theCriteria->length();
1365 theCriteria->length( i + 1 );
1367 theCriteria[ i ] = createCriterion();
1369 theCriteria[ i ].Type = aFType;
1370 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
1373 case FT_BelongToGeom:
1375 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
1377 CORBA::ULong i = theCriteria->length();
1378 theCriteria->length( i + 1 );
1380 theCriteria[ i ] = createCriterion();
1382 theCriteria[ i ].Type = FT_BelongToGeom;
1383 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1384 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1388 case FT_BelongToPlane:
1389 case FT_BelongToCylinder:
1391 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
1393 CORBA::ULong i = theCriteria->length();
1394 theCriteria->length( i + 1 );
1396 theCriteria[ i ] = createCriterion();
1398 theCriteria[ i ].Type = aFType;
1399 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1400 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1401 theCriteria[ i ].Tolerance = aPred->GetTolerance();
1407 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
1409 CORBA::ULong i = theCriteria->length();
1410 theCriteria->length( i + 1 );
1412 theCriteria[ i ] = createCriterion();
1414 theCriteria[ i ].Type = FT_RangeOfIds;
1415 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
1416 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1424 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
1426 CORBA::ULong i = theCriteria->length();
1427 theCriteria->length( i + 1 );
1429 theCriteria[ i ] = createCriterion();
1431 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
1432 theCriteria[ i ].Compare = aFType;
1433 theCriteria[ i ].Threshold = aCompar->GetMargin();
1434 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
1436 if ( aFType == FT_EqualTo )
1438 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
1439 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
1446 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
1447 getCriteria( aPred, theCriteria );
1448 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
1455 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
1456 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
1457 if ( !getCriteria( aPred1, theCriteria ) )
1459 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
1460 return getCriteria( aPred2, theCriteria );
1470 //=======================================================================
1471 // name : Filter_i::GetCriteria
1472 // Purpose : Retrieve criterions from predicate
1473 //=======================================================================
1474 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
1476 theCriteria = new SMESH::Filter::Criteria;
1477 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
1480 //=======================================================================
1481 // name : Filter_i::SetCriteria
1482 // Purpose : Create new predicate and set criterions in it
1483 //=======================================================================
1484 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
1486 if ( myPredicate != 0 )
1487 myPredicate->Destroy();
1489 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1490 FilterManager_ptr aFilterMgr = aFilter->_this();
1492 // CREATE two lists ( PREDICATES and LOG OP )
1495 std::list<SMESH::Predicate_ptr> aPredicates;
1496 std::list<int> aBinaries;
1497 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
1499 int aCriterion = theCriteria[ i ].Type;
1500 int aCompare = theCriteria[ i ].Compare;
1501 double aThreshold = theCriteria[ i ].Threshold;
1502 int aUnary = theCriteria[ i ].UnaryOp;
1503 int aBinary = theCriteria[ i ].BinaryOp;
1504 double aTolerance = theCriteria[ i ].Tolerance;
1505 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
1506 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
1507 long aPrecision = theCriteria[ i ].Precision;
1509 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
1510 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
1512 switch ( aCriterion )
1516 case SMESH::FT_MultiConnection:
1517 aFunctor = aFilterMgr->CreateMultiConnection();
1519 case SMESH::FT_MultiConnection2D:
1520 aFunctor = aFilterMgr->CreateMultiConnection2D();
1522 case SMESH::FT_Length:
1523 aFunctor = aFilterMgr->CreateLength();
1525 case SMESH::FT_Length2D:
1526 aFunctor = aFilterMgr->CreateLength2D();
1528 case SMESH::FT_AspectRatio:
1529 aFunctor = aFilterMgr->CreateAspectRatio();
1531 case SMESH::FT_AspectRatio3D:
1532 aFunctor = aFilterMgr->CreateAspectRatio3D();
1534 case SMESH::FT_Warping:
1535 aFunctor = aFilterMgr->CreateWarping();
1537 case SMESH::FT_MinimumAngle:
1538 aFunctor = aFilterMgr->CreateMinimumAngle();
1540 case SMESH::FT_Taper:
1541 aFunctor = aFilterMgr->CreateTaper();
1543 case SMESH::FT_Skew:
1544 aFunctor = aFilterMgr->CreateSkew();
1546 case SMESH::FT_Area:
1547 aFunctor = aFilterMgr->CreateArea();
1552 case SMESH::FT_FreeBorders:
1553 aPredicate = aFilterMgr->CreateFreeBorders();
1555 case SMESH::FT_FreeEdges:
1556 aPredicate = aFilterMgr->CreateFreeEdges();
1558 case SMESH::FT_BelongToGeom:
1560 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
1561 tmpPred->SetElementType( aTypeOfElem );
1562 tmpPred->SetShapeName( aThresholdStr );
1563 aPredicate = tmpPred;
1566 case SMESH::FT_BelongToPlane:
1567 case SMESH::FT_BelongToCylinder:
1569 SMESH::BelongToSurface_ptr tmpPred;
1570 if ( aCriterion == SMESH::FT_BelongToPlane )
1571 tmpPred = aFilterMgr->CreateBelongToPlane();
1573 tmpPred = aFilterMgr->CreateBelongToCylinder();
1574 tmpPred->SetShapeName( aThresholdStr, aTypeOfElem );
1575 tmpPred->SetTolerance( aTolerance );
1576 aPredicate = tmpPred;
1579 case SMESH::FT_RangeOfIds:
1581 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
1582 tmpPred->SetRangeStr( aThresholdStr );
1583 tmpPred->SetElementType( aTypeOfElem );
1584 aPredicate = tmpPred;
1593 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
1595 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
1597 if ( aCompare == SMESH::FT_LessThan )
1598 aComparator = aFilterMgr->CreateLessThan();
1599 else if ( aCompare == SMESH::FT_MoreThan )
1600 aComparator = aFilterMgr->CreateMoreThan();
1601 else if ( aCompare == SMESH::FT_EqualTo )
1602 aComparator = aFilterMgr->CreateEqualTo();
1606 aComparator->SetNumFunctor( aFunctor );
1607 aComparator->SetMargin( aThreshold );
1609 if ( aCompare == FT_EqualTo )
1611 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
1612 anEqualTo->SetTolerance( aTolerance );
1615 aPredicate = aComparator;
1617 aFunctor->SetPrecision( aPrecision );
1621 if ( aUnary == FT_LogicalNOT )
1623 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
1624 aNotPred->SetPredicate( aPredicate );
1625 aPredicate = aNotPred;
1629 aPredicates.push_back( aPredicate );
1630 aBinaries.push_back( aBinary );
1634 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
1636 // combine all "AND" operations
1638 std::list<SMESH::Predicate_ptr> aResList;
1640 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
1641 std::list<int>::iterator aBinaryIter;
1643 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
1644 int aPrevBinary = SMESH::FT_Undefined;
1646 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
1647 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
1648 ++aPredIter, ++aBinaryIter )
1650 int aCurrBinary = *aBinaryIter;
1652 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
1654 if ( aPrevBinary == SMESH::FT_LogicalAND )
1657 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
1658 aBinaryPred->SetPredicate1( aPrevPredicate );
1659 aBinaryPred->SetPredicate2( *aPredIter );
1660 aCurrPred = aBinaryPred;
1663 aCurrPred = *aPredIter;
1665 if ( aCurrBinary != SMESH::FT_LogicalAND )
1666 aResList.push_back( aCurrPred );
1668 aPrevPredicate = aCurrPred;
1669 aPrevBinary = aCurrBinary;
1672 // combine all "OR" operations
1674 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
1676 if ( aResList.size() == 1 )
1677 aResPredicate = *aResList.begin();
1678 else if ( aResList.size() > 1 )
1680 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
1681 aResPredicate = *anIter;
1683 for ( ; anIter != aResList.end(); ++anIter )
1685 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
1686 aBinaryPred->SetPredicate1( aResPredicate );
1687 aBinaryPred->SetPredicate2( *anIter );
1688 aResPredicate = aBinaryPred;
1692 SetPredicate( aResPredicate );
1694 return !aResPredicate->_is_nil();
1697 //=======================================================================
1698 // name : Filter_i::GetPredicate_i
1699 // Purpose : Get implementation of predicate
1700 //=======================================================================
1701 Predicate_i* Filter_i::GetPredicate_i()
1706 //=======================================================================
1707 // name : Filter_i::GetPredicate
1708 // Purpose : Get predicate
1709 //=======================================================================
1710 Predicate_ptr Filter_i::GetPredicate()
1712 if ( myPredicate == 0 )
1713 return SMESH::Predicate::_nil();
1716 SMESH::Predicate_var anObj = myPredicate->_this();
1717 return anObj._retn();
1725 #define ATTR_TYPE "type"
1726 #define ATTR_COMPARE "compare"
1727 #define ATTR_THRESHOLD "threshold"
1728 #define ATTR_UNARY "unary"
1729 #define ATTR_BINARY "binary"
1730 #define ATTR_THRESHOLD_STR "threshold_str"
1731 #define ATTR_TOLERANCE "tolerance"
1732 #define ATTR_ELEMENT_TYPE "ElementType"
1734 //=======================================================================
1736 // Purpose : Convert bool to LDOMString
1737 //=======================================================================
1738 static inline LDOMString toString( const bool val )
1740 return val ? "logical not" : "";
1743 //=======================================================================
1745 // Purpose : Convert LDOMString to bool
1746 //=======================================================================
1747 static inline bool toBool( const LDOMString& theStr )
1749 return theStr.equals( "logical not" );
1752 //=======================================================================
1754 // Purpose : Convert double to LDOMString
1755 //=======================================================================
1756 static inline LDOMString toString( const double val )
1759 sprintf( a, "%e", val );
1760 return LDOMString( a );
1763 //=======================================================================
1765 // Purpose : Convert LDOMString to double
1766 //=======================================================================
1767 static inline double toDouble( const LDOMString& theStr )
1769 return atof( theStr.GetString() );
1772 //=======================================================================
1774 // Purpose : Convert functor type to LDOMString
1775 //=======================================================================
1776 static inline LDOMString toString( const long theType )
1780 case FT_AspectRatio : return "Aspect ratio";
1781 case FT_Warping : return "Warping";
1782 case FT_MinimumAngle : return "Minimum angle";
1783 case FT_Taper : return "Taper";
1784 case FT_Skew : return "Skew";
1785 case FT_Area : return "Area";
1786 case FT_BelongToGeom : return "Belong to Geom";
1787 case FT_BelongToPlane : return "Belong to Plane";
1788 case FT_BelongToCylinder: return "Belong to Cylinder";
1789 case FT_RangeOfIds : return "Range of IDs";
1790 case FT_FreeBorders : return "Free borders";
1791 case FT_FreeEdges : return "Free edges";
1792 case FT_MultiConnection : return "Borders at multi-connections";
1793 case FT_MultiConnection2D: return "Borders at multi-connections 2D";
1794 case FT_Length : return "Length";
1795 case FT_Length2D : return "Length2D";
1796 case FT_LessThan : return "Less than";
1797 case FT_MoreThan : return "More than";
1798 case FT_EqualTo : return "Equal to";
1799 case FT_LogicalNOT : return "Not";
1800 case FT_LogicalAND : return "And";
1801 case FT_LogicalOR : return "Or";
1802 case FT_Undefined : return "";
1803 default : return "";
1807 //=======================================================================
1808 // name : toFunctorType
1809 // Purpose : Convert LDOMString to functor type
1810 //=======================================================================
1811 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
1813 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
1814 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
1815 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
1816 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
1817 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
1818 else if ( theStr.equals( "Area" ) ) return FT_Area;
1819 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
1820 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
1821 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
1822 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
1823 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
1824 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
1825 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
1826 else if ( theStr.equals( "Length" ) ) return FT_Length;
1827 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
1828 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
1829 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
1830 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
1831 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
1832 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
1833 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
1834 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
1835 else if ( theStr.equals( "" ) ) return FT_Undefined;
1836 else return FT_Undefined;
1839 //=======================================================================
1840 // name : toFunctorType
1841 // Purpose : Convert LDOMString to value of ElementType enumeration
1842 //=======================================================================
1843 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
1845 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
1846 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
1847 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
1848 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
1849 else return SMESH::ALL;
1852 //=======================================================================
1854 // Purpose : Convert ElementType to string
1855 //=======================================================================
1856 static inline LDOMString toString( const SMESH::ElementType theType )
1860 case SMESH::NODE : return "NODE";
1861 case SMESH::EDGE : return "EDGE";
1862 case SMESH::FACE : return "FACE";
1863 case SMESH::VOLUME : return "VOLUME";
1864 case SMESH::ALL : return "ALL";
1865 default : return "";
1869 //=======================================================================
1870 // name : findFilter
1871 // Purpose : Find filter in document
1872 //=======================================================================
1873 static LDOM_Element findFilter( const char* theFilterName,
1874 const LDOM_Document& theDoc,
1875 LDOM_Node* theParent = 0 )
1877 LDOM_Element aRootElement = theDoc.getDocumentElement();
1878 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
1879 return LDOM_Element();
1881 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
1882 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
1884 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
1885 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
1887 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
1888 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
1889 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
1891 if ( theParent != 0 )
1892 *theParent = aTypeNode;
1893 return (LDOM_Element&)aFilter;
1897 return LDOM_Element();
1900 //=======================================================================
1901 // name : getSectionName
1902 // Purpose : Get name of section of filters
1903 //=======================================================================
1904 static const char* getSectionName( const ElementType theType )
1908 case SMESH::NODE : return "Filters for nodes";
1909 case SMESH::EDGE : return "Filters for edges";
1910 case SMESH::FACE : return "Filters for faces";
1911 case SMESH::VOLUME : return "Filters for volumes";
1912 case SMESH::ALL : return "Filters for elements";
1913 default : return "";
1917 //=======================================================================
1918 // name : getSection
1919 // Purpose : Create section for filters corresponding to the entity type
1920 //=======================================================================
1921 static LDOM_Node getSection( const ElementType theType,
1922 LDOM_Document& theDoc,
1923 const bool toCreate = false )
1925 LDOM_Element aRootElement = theDoc.getDocumentElement();
1926 if ( aRootElement.isNull() )
1930 bool anExist = false;
1931 const char* aSectionName = getSectionName( theType );
1932 if ( strcmp( aSectionName, "" ) == 0 )
1935 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
1937 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
1939 aNode = aSections.item( i );
1940 LDOM_Element& anItem = ( LDOM_Element& )aNode;
1941 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
1948 // Create new section if necessary
1953 LDOM_Element aNewItem = theDoc.createElement( "section" );
1954 aNewItem.setAttribute( "name", aSectionName );
1955 aRootElement.appendChild( aNewItem );
1965 //=======================================================================
1966 // name : createFilterItem
1967 // Purpose : Create filter item or LDOM document
1968 //=======================================================================
1969 static LDOM_Element createFilterItem( const char* theName,
1970 SMESH::Filter_ptr theFilter,
1971 LDOM_Document& theDoc )
1973 // create new filter in document
1974 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
1975 aFilterItem.setAttribute( "name", theName );
1977 // save filter criterions
1978 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
1980 if ( !theFilter->GetCriteria( aCriteria ) )
1981 return LDOM_Element();
1983 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
1985 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
1987 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type ) );
1988 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
1989 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
1990 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
1991 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
1993 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
1994 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
1995 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
1996 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
1998 aFilterItem.appendChild( aCriterionItem );
2004 //=======================================================================
2005 // name : FilterLibrary_i::FilterLibrary_i
2006 // Purpose : Constructor
2007 //=======================================================================
2008 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
2010 myFileName = strdup( theFileName );
2011 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
2012 myFilterMgr = aFilterMgr->_this();
2016 // Try to use existing library file
2017 bool anExists = false;
2018 if ( !aParser.parse( myFileName ) )
2020 myDoc = aParser.getDocument();
2023 // Create a new XML document if it doesn't exist
2025 myDoc = LDOM_Document::createDocument( LDOMString() );
2027 LDOM_Element aRootElement = myDoc.getDocumentElement();
2028 if ( aRootElement.isNull() )
2030 // If the existing document is empty --> try to create a new one
2032 myDoc = LDOM_Document::createDocument( LDOMString() );
2036 //=======================================================================
2037 // name : FilterLibrary_i::FilterLibrary_i
2038 // Purpose : Constructor
2039 //=======================================================================
2040 FilterLibrary_i::FilterLibrary_i()
2043 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2044 myFilterMgr = aFilter->_this();
2046 myDoc = LDOM_Document::createDocument( LDOMString() );
2049 FilterLibrary_i::~FilterLibrary_i()
2054 //=======================================================================
2055 // name : FilterLibrary_i::Copy
2056 // Purpose : Create filter and initialize it with values from library
2057 //=======================================================================
2058 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
2061 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
2063 if ( aFilter.isNull() )
2066 std::list<SMESH::Filter::Criterion> aCriteria;
2068 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
2069 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
2071 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
2073 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
2074 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
2075 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
2076 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
2077 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
2079 SMESH::Filter::Criterion aCriterion = createCriterion();
2081 aCriterion.Type = toFunctorType( aTypeStr );
2082 aCriterion.Compare = toFunctorType( aCompareStr );
2083 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
2084 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
2086 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
2088 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
2090 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2091 ? val : atof( str.GetString() );
2093 str = aCrit->getAttribute( ATTR_TOLERANCE );
2094 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2095 ? val : atof( str.GetString() );
2097 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
2098 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
2101 sprintf( a, "%d", val );
2102 aCriterion.ThresholdStr = strdup( a );
2105 aCriterion.ThresholdStr = str.GetString();
2107 aCriteria.push_back( aCriterion );
2110 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
2111 aCriteriaVar->length( aCriteria.size() );
2114 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
2116 for( ; anIter != aCriteria.end(); ++anIter )
2117 aCriteriaVar[ i++ ] = *anIter;
2119 aRes = myFilterMgr->CreateFilter();
2120 aRes->SetCriteria( aCriteriaVar.inout() );
2125 //=======================================================================
2126 // name : FilterLibrary_i::SetFileName
2127 // Purpose : Set file name for library
2128 //=======================================================================
2129 void FilterLibrary_i::SetFileName( const char* theFileName )
2132 myFileName = strdup( theFileName );
2135 //=======================================================================
2136 // name : FilterLibrary_i::GetFileName
2137 // Purpose : Get file name of library
2138 //=======================================================================
2139 char* FilterLibrary_i::GetFileName()
2141 return CORBA::string_dup( myFileName );
2144 //=======================================================================
2145 // name : FilterLibrary_i::Add
2146 // Purpose : Add new filter to library
2147 //=======================================================================
2148 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
2150 // if filter already in library or entry filter is null do nothing
2151 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2152 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
2155 // get section corresponding to the filter type
2156 ElementType anEntType = theFilter->GetElementType();
2158 LDOM_Node aSection = getSection( anEntType, myDoc, true );
2159 if ( aSection.isNull() )
2162 // create filter item
2163 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
2164 if ( aFilterItem.isNull() )
2168 aSection.appendChild( aFilterItem );
2173 //=======================================================================
2174 // name : FilterLibrary_i::Add
2175 // Purpose : Add new filter to library
2176 //=======================================================================
2177 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
2179 // if filter already in library or entry filter is null do nothing
2180 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2181 if ( !aFilterNode.isNull() )
2184 LDOM_Node aSection = getSection( theType, myDoc, true );
2185 if ( aSection.isNull() )
2188 // create filter item
2189 Filter_var aFilter = myFilterMgr->CreateFilter();
2191 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
2192 if ( aFilterItem.isNull() )
2196 aSection.appendChild( aFilterItem );
2201 //=======================================================================
2202 // name : FilterLibrary_i::Delete
2203 // Purpose : Delete filter from library
2204 //=======================================================================
2205 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
2207 LDOM_Node aParentNode;
2208 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
2209 if ( aFilterNode.isNull() || aParentNode.isNull() )
2212 aParentNode.removeChild( aFilterNode );
2216 //=======================================================================
2217 // name : FilterLibrary_i::Replace
2218 // Purpose : Replace existing filter with entry filter.
2219 // IMPORTANT : If filter does not exist it is not created
2220 //=======================================================================
2221 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
2222 const char* theNewName,
2223 Filter_ptr theFilter )
2225 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
2226 if ( aFilterItem.isNull() || theFilter->_is_nil() )
2229 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
2230 if ( aNewItem.isNull() )
2234 aFilterItem.ReplaceElement( aNewItem );
2239 //=======================================================================
2240 // name : FilterLibrary_i::Save
2241 // Purpose : Save library on disk
2242 //=======================================================================
2243 CORBA::Boolean FilterLibrary_i::Save()
2245 if ( myFileName == 0 || strlen( myFileName ) == 0 )
2248 FILE* aOutFile = fopen( myFileName, "wt" );
2252 LDOM_XmlWriter aWriter( aOutFile );
2253 aWriter.SetIndentation( 2 );
2260 //=======================================================================
2261 // name : FilterLibrary_i::SaveAs
2262 // Purpose : Save library on disk
2263 //=======================================================================
2264 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
2266 myFileName = strdup ( aFileName );
2270 //=======================================================================
2271 // name : FilterLibrary_i::IsPresent
2272 // Purpose : Verify whether filter is in library
2273 //=======================================================================
2274 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
2276 return !findFilter( theFilterName, myDoc ).isNull();
2279 //=======================================================================
2280 // name : FilterLibrary_i::NbFilters
2281 // Purpose : Return amount of filters in library
2282 //=======================================================================
2283 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
2285 string_array_var aNames = GetNames( theType );
2286 return aNames->length();
2289 //=======================================================================
2290 // name : FilterLibrary_i::GetNames
2291 // Purpose : Get names of filters from library
2292 //=======================================================================
2293 string_array* FilterLibrary_i::GetNames( ElementType theType )
2295 string_array_var anArray = new string_array;
2296 TColStd_SequenceOfHAsciiString aSeq;
2298 LDOM_Node aSection = getSection( theType, myDoc, false );
2300 if ( !aSection.isNull() )
2302 for ( LDOM_Node aFilter = aSection.getFirstChild();
2303 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2305 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
2306 aSeq.Append( new TCollection_HAsciiString(
2307 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
2311 anArray->length( aSeq.Length() );
2312 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
2313 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
2315 return anArray._retn();
2318 //=======================================================================
2319 // name : FilterLibrary_i::GetAllNames
2320 // Purpose : Get names of filters from library
2321 //=======================================================================
2322 string_array* FilterLibrary_i::GetAllNames()
2324 string_array_var aResArray = new string_array;
2325 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
2327 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
2329 int aPrevLength = aResArray->length();
2330 aResArray->length( aPrevLength + aNames->length() );
2331 for ( int i = 0, n = aNames->length(); i < n; i++ )
2332 aResArray[ aPrevLength + i ] = aNames[ i ];
2335 return aResArray._retn();