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;
339 Description : Functor for calculating warping
341 Warping_i::Warping_i()
343 myNumericalFunctorPtr.reset( new Controls::Warping() );
344 myFunctorPtr = myNumericalFunctorPtr;
347 FunctorType Warping_i::GetFunctorType()
349 return SMESH::FT_Warping;
355 Description : Functor for calculating taper
359 myNumericalFunctorPtr.reset( new Controls::Taper() );
360 myFunctorPtr = myNumericalFunctorPtr;
363 FunctorType Taper_i::GetFunctorType()
365 return SMESH::FT_Taper;
371 Description : Functor for calculating skew in degrees
375 myNumericalFunctorPtr.reset( new Controls::Skew() );
376 myFunctorPtr = myNumericalFunctorPtr;
379 FunctorType Skew_i::GetFunctorType()
381 return SMESH::FT_Skew;
386 Description : Functor for calculating area
390 myNumericalFunctorPtr.reset( new Controls::Area() );
391 myFunctorPtr = myNumericalFunctorPtr;
394 FunctorType Area_i::GetFunctorType()
396 return SMESH::FT_Area;
401 Description : Functor for calculating length off edge
405 myNumericalFunctorPtr.reset( new Controls::Length() );
406 myFunctorPtr = myNumericalFunctorPtr;
409 FunctorType Length_i::GetFunctorType()
411 return SMESH::FT_Length;
415 Class : MultiConnection_i
416 Description : Functor for calculating number of faces conneted to the edge
418 MultiConnection_i::MultiConnection_i()
420 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
421 myFunctorPtr = myNumericalFunctorPtr;
424 FunctorType MultiConnection_i::GetFunctorType()
426 return SMESH::FT_MultiConnection;
437 Description : Base class for all predicates
439 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
441 return myPredicatePtr->IsSatisfy( theId );
444 Controls::PredicatePtr Predicate_i::GetPredicate()
446 return myPredicatePtr;
451 Class : BelongToGeom_i
452 Description : Predicate for selection on geometrical support
454 BelongToGeom_i::BelongToGeom_i()
456 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
457 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
461 BelongToGeom_i::~BelongToGeom_i()
466 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
468 if ( theGeom->_is_nil() )
470 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
471 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
472 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
473 myBelongToGeomPtr->SetGeom( aLocShape );
476 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
478 myBelongToGeomPtr->SetGeom( theShape );
481 void BelongToGeom_i::SetElementType(ElementType theType){
482 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
485 FunctorType BelongToGeom_i::GetFunctorType()
487 return SMESH::FT_BelongToGeom;
490 void BelongToGeom_i::SetShapeName( const char* theName )
493 myShapeName = strdup( theName );
494 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
497 char* BelongToGeom_i::GetShapeName()
499 return CORBA::string_dup( myShapeName );
503 Class : BelongToSurface_i
504 Description : Predicate for selection on geometrical support
506 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
508 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
509 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
511 mySurfaceType = theSurfaceType;
514 BelongToSurface_i::~BelongToSurface_i()
519 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
521 if ( theGeom->_is_nil() )
523 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
524 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
525 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
527 if ( aLocShape.ShapeType() == TopAbs_FACE )
529 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
530 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
532 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
537 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
540 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
543 myShapeName = strdup( theName );
544 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
547 char* BelongToSurface_i::GetShapeName()
549 return CORBA::string_dup( myShapeName );
552 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
554 myElementsOnSurfacePtr->SetTolerance( theToler );
557 CORBA::Double BelongToSurface_i::GetTolerance()
559 return myElementsOnSurfacePtr->GetTolerance();
563 Class : BelongToPlane_i
564 Description : Verify whether mesh element lie in pointed Geom planar object
567 BelongToPlane_i::BelongToPlane_i()
568 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
572 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
574 BelongToSurface_i::SetSurface( theGeom, theType );
577 FunctorType BelongToPlane_i::GetFunctorType()
579 return FT_BelongToPlane;
583 Class : BelongToCylinder_i
584 Description : Verify whether mesh element lie in pointed Geom planar object
587 BelongToCylinder_i::BelongToCylinder_i()
588 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
592 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
594 BelongToSurface_i::SetSurface( theGeom, theType );
597 FunctorType BelongToCylinder_i::GetFunctorType()
599 return FT_BelongToCylinder;
605 Class : FreeBorders_i
606 Description : Predicate for free borders
608 FreeBorders_i::FreeBorders_i()
610 myPredicatePtr.reset(new Controls::FreeBorders());
611 myFunctorPtr = myPredicatePtr;
614 FunctorType FreeBorders_i::GetFunctorType()
616 return SMESH::FT_FreeBorders;
621 Description : Predicate for free borders
623 FreeEdges_i::FreeEdges_i()
624 : myFreeEdgesPtr( new Controls::FreeEdges() )
626 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
629 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
631 INFOS("FreeEdges_i::GetBorders");
632 SMESH::Controls::FreeEdges::TBorders aBorders;
633 myFreeEdgesPtr->GetBoreders( aBorders );
635 long i = 0, iEnd = aBorders.size();
637 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders(iEnd);
639 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
640 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
642 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
643 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
645 aBorder.myElemId = aBord.myElemId;
646 aBorder.myPnt1 = aBord.myPntId[ 0 ];
647 aBorder.myPnt2 = aBord.myPntId[ 1 ];
650 INFOS("FreeEdges_i::GetBorders~");
651 return aResult._retn();
654 FunctorType FreeEdges_i::GetFunctorType()
656 return SMESH::FT_FreeEdges;
661 Description : Predicate for Range of Ids.
662 Range may be specified with two ways.
663 1. Using AddToRange method
664 2. With SetRangeStr method. Parameter of this method is a string
665 like as "1,2,3,50-60,63,67,70-"
668 RangeOfIds_i::RangeOfIds_i()
670 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
671 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
674 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
676 CORBA::Long iEnd = theIds.length();
677 for ( CORBA::Long i = 0; i < iEnd; i++ )
678 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
681 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
683 return myRangeOfIdsPtr->SetRangeStr(
684 TCollection_AsciiString( (Standard_CString)theRange ) );
687 char* RangeOfIds_i::GetRangeStr()
689 TCollection_AsciiString aStr;
690 myRangeOfIdsPtr->GetRangeStr( aStr );
691 return CORBA::string_dup( aStr.ToCString() );
694 void RangeOfIds_i::SetElementType( ElementType theType )
696 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
699 FunctorType RangeOfIds_i::GetFunctorType()
701 return SMESH::FT_RangeOfIds;
706 Description : Base class for comparators
708 Comparator_i::Comparator_i():
709 myNumericalFunctor( NULL )
712 Comparator_i::~Comparator_i()
714 if ( myNumericalFunctor )
715 myNumericalFunctor->Destroy();
718 void Comparator_i::SetMargin( CORBA::Double theValue )
720 myComparatorPtr->SetMargin( theValue );
723 CORBA::Double Comparator_i::GetMargin()
725 return myComparatorPtr->GetMargin();
728 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
730 if ( myNumericalFunctor )
731 myNumericalFunctor->Destroy();
733 myNumericalFunctor = dynamic_cast<NumericalFunctor_i*>( SMESH_Gen_i::GetServant( theFunct ).in() );
735 if ( myNumericalFunctor )
737 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
738 myNumericalFunctor->Register();
742 Controls::ComparatorPtr Comparator_i::GetComparator()
744 return myComparatorPtr;
747 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
749 return myNumericalFunctor;
755 Description : Comparator "<"
757 LessThan_i::LessThan_i()
759 myComparatorPtr.reset( new Controls::LessThan() );
760 myFunctorPtr = myPredicatePtr = myComparatorPtr;
763 FunctorType LessThan_i::GetFunctorType()
765 return SMESH::FT_LessThan;
771 Description : Comparator ">"
773 MoreThan_i::MoreThan_i()
775 myComparatorPtr.reset( new Controls::MoreThan() );
776 myFunctorPtr = myPredicatePtr = myComparatorPtr;
779 FunctorType MoreThan_i::GetFunctorType()
781 return SMESH::FT_MoreThan;
787 Description : Comparator "="
789 EqualTo_i::EqualTo_i()
790 : myEqualToPtr( new Controls::EqualTo() )
792 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
795 void EqualTo_i::SetTolerance( CORBA::Double theToler )
797 myEqualToPtr->SetTolerance( theToler );
800 CORBA::Double EqualTo_i::GetTolerance()
802 return myEqualToPtr->GetTolerance();
805 FunctorType EqualTo_i::GetFunctorType()
807 return SMESH::FT_EqualTo;
812 Description : Logical NOT predicate
814 LogicalNOT_i::LogicalNOT_i()
815 : myPredicate( NULL ),
816 myLogicalNOTPtr( new Controls::LogicalNOT() )
818 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
821 LogicalNOT_i::~LogicalNOT_i()
824 myPredicate->Destroy();
827 void LogicalNOT_i::SetPredicate( Predicate_ptr thePred )
830 myPredicate->Destroy();
832 myPredicate = dynamic_cast<Predicate_i*>( SMESH_Gen_i::GetServant( thePred ).in() );
835 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
836 myPredicate->Register();
840 FunctorType LogicalNOT_i::GetFunctorType()
842 return SMESH::FT_LogicalNOT;
845 Predicate_i* LogicalNOT_i::GetPredicate_i()
852 Class : LogicalBinary_i
853 Description : Base class for binary logical predicate
855 LogicalBinary_i::LogicalBinary_i()
856 : myPredicate1( NULL ),
860 LogicalBinary_i::~LogicalBinary_i()
863 myPredicate1->Destroy();
866 myPredicate2->Destroy();
869 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
872 myPredicate1->SetMesh( theMesh );
875 myPredicate2->SetMesh( theMesh );
878 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
881 myPredicate1->Destroy();
883 myPredicate1 = dynamic_cast<Predicate_i*>( SMESH_Gen_i::GetServant( thePredicate ).in() );
886 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
887 myPredicate1->Register();
891 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
894 myPredicate2->Destroy();
896 myPredicate2 = dynamic_cast<Predicate_i*>( SMESH_Gen_i::GetServant( thePredicate ).in() );
899 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
900 myPredicate2->Register();
904 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
906 return myLogicalBinaryPtr;
909 Predicate_i* LogicalBinary_i::GetPredicate1_i()
913 Predicate_i* LogicalBinary_i::GetPredicate2_i()
921 Description : Logical AND
923 LogicalAND_i::LogicalAND_i()
925 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
926 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
929 FunctorType LogicalAND_i::GetFunctorType()
931 return SMESH::FT_LogicalAND;
937 Description : Logical OR
939 LogicalOR_i::LogicalOR_i()
941 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
942 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
945 FunctorType LogicalOR_i::GetFunctorType()
947 return SMESH::FT_LogicalOR;
955 FilterManager_i::FilterManager_i()
956 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
958 SMESH_Gen_i::GetPOA()->activate_object( this );
961 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
963 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
964 SMESH::MinimumAngle_var anObj = aServant->_this();
965 return anObj._retn();
969 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
971 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
972 SMESH::AspectRatio_var anObj = aServant->_this();
973 return anObj._retn();
977 Warping_ptr FilterManager_i::CreateWarping()
979 SMESH::Warping_i* aServant = new SMESH::Warping_i();
980 SMESH::Warping_var anObj = aServant->_this();
981 return anObj._retn();
985 Taper_ptr FilterManager_i::CreateTaper()
987 SMESH::Taper_i* aServant = new SMESH::Taper_i();
988 SMESH::Taper_var anObj = aServant->_this();
989 return anObj._retn();
993 Skew_ptr FilterManager_i::CreateSkew()
995 SMESH::Skew_i* aServant = new SMESH::Skew_i();
996 SMESH::Skew_var anObj = aServant->_this();
997 return anObj._retn();
1001 Area_ptr FilterManager_i::CreateArea()
1003 SMESH::Area_i* aServant = new SMESH::Area_i();
1004 SMESH::Area_var anObj = aServant->_this();
1005 return anObj._retn();
1009 Length_ptr FilterManager_i::CreateLength()
1011 SMESH::Length_i* aServant = new SMESH::Length_i();
1012 SMESH::Length_var anObj = aServant->_this();
1013 return anObj._retn();
1017 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1019 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1020 SMESH::MultiConnection_var anObj = aServant->_this();
1021 return anObj._retn();
1025 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1027 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1028 SMESH::BelongToGeom_var anObj = aServant->_this();
1029 return anObj._retn();
1032 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1034 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1035 SMESH::BelongToPlane_var anObj = aServant->_this();
1036 return anObj._retn();
1039 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1041 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1042 SMESH::BelongToCylinder_var anObj = aServant->_this();
1043 return anObj._retn();
1046 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1048 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1049 SMESH::FreeBorders_var anObj = aServant->_this();
1050 return anObj._retn();
1053 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1055 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1056 SMESH::FreeEdges_var anObj = aServant->_this();
1057 return anObj._retn();
1060 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1062 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1063 SMESH::RangeOfIds_var anObj = aServant->_this();
1064 return anObj._retn();
1067 LessThan_ptr FilterManager_i::CreateLessThan()
1069 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1070 SMESH::LessThan_var anObj = aServant->_this();
1071 return anObj._retn();
1075 MoreThan_ptr FilterManager_i::CreateMoreThan()
1077 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1078 SMESH::MoreThan_var anObj = aServant->_this();
1079 return anObj._retn();
1082 EqualTo_ptr FilterManager_i::CreateEqualTo()
1084 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1085 SMESH::EqualTo_var anObj = aServant->_this();
1086 return anObj._retn();
1090 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1092 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1093 SMESH::LogicalNOT_var anObj = aServant->_this();
1094 return anObj._retn();
1098 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
1100 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
1101 SMESH::LogicalAND_var anObj = aServant->_this();
1102 return anObj._retn();
1106 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
1108 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
1109 SMESH::LogicalOR_var anObj = aServant->_this();
1110 return anObj._retn();
1113 Filter_ptr FilterManager_i::CreateFilter()
1115 SMESH::Filter_i* aServant = new SMESH::Filter_i();
1116 SMESH::Filter_var anObj = aServant->_this();
1117 return anObj._retn();
1120 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
1122 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
1123 SMESH::FilterLibrary_var anObj = aServant->_this();
1124 return anObj._retn();
1127 FilterLibrary_ptr FilterManager_i::CreateLibrary()
1129 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
1130 SMESH::FilterLibrary_var anObj = aServant->_this();
1131 return anObj._retn();
1134 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
1136 return remove( aFileName ) ? false : true;
1139 //=============================================================================
1141 * SMESH_Gen_i::CreateFilterManager
1143 * Create filter manager
1145 //=============================================================================
1147 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
1149 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1150 SMESH::FilterManager_var anObj = aFilter->_this();
1151 return anObj._retn();
1159 //=======================================================================
1160 // name : Filter_i::Filter_i
1161 // Purpose : Constructor
1162 //=======================================================================
1163 Filter_i::Filter_i()
1164 : myPredicate( NULL )
1167 //=======================================================================
1168 // name : Filter_i::~Filter_i
1169 // Purpose : Destructor
1170 //=======================================================================
1171 Filter_i::~Filter_i()
1174 myPredicate->Destroy();
1177 //=======================================================================
1178 // name : Filter_i::SetPredicate
1179 // Purpose : Set predicate
1180 //=======================================================================
1181 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
1184 myPredicate->Destroy();
1186 myPredicate = dynamic_cast<Predicate_i*>( SMESH_Gen_i::GetServant( thePredicate ).in() );
1190 myFilter.SetPredicate( myPredicate->GetPredicate() );
1191 myPredicate->Register();
1195 //=======================================================================
1196 // name : Filter_i::GetElementType
1197 // Purpose : Get entity type
1198 //=======================================================================
1199 SMESH::ElementType Filter_i::GetElementType()
1201 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
1204 //=======================================================================
1205 // name : Filter_i::SetMesh
1206 // Purpose : Set mesh
1207 //=======================================================================
1208 void Filter_i::SetMesh( SMESH_Mesh_ptr theMesh )
1211 myPredicate->SetMesh( theMesh );
1214 //=======================================================================
1215 // name : Filter_i::GetElementsId
1216 // Purpose : Get ids of entities
1217 //=======================================================================
1218 SMESH::long_array* Filter_i::GetElementsId( SMESH_Mesh_ptr theMesh )
1220 SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh);
1221 Controls::Filter::TIdSequence aSequence = myFilter.GetElementsId(aMesh);
1223 SMESH::long_array_var anArray = new SMESH::long_array;
1224 long i = 0, iEnd = aSequence.size();
1226 anArray->length( iEnd );
1227 for ( ; i < iEnd; i++ )
1228 anArray[ i ] = aSequence[i];
1230 return anArray._retn();
1233 //=======================================================================
1234 // name : getCriteria
1235 // Purpose : Retrieve criterions from predicate
1236 //=======================================================================
1237 static inline bool getCriteria( Predicate_i* thePred,
1238 SMESH::Filter::Criteria_out theCriteria )
1240 int aFType = thePred->GetFunctorType();
1244 case FT_FreeBorders:
1247 CORBA::ULong i = theCriteria->length();
1248 theCriteria->length( i + 1 );
1250 theCriteria[ i ] = createCriterion();
1252 theCriteria[ i ].Type = aFType;
1253 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
1256 case FT_BelongToGeom:
1258 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
1260 CORBA::ULong i = theCriteria->length();
1261 theCriteria->length( i + 1 );
1263 theCriteria[ i ] = createCriterion();
1265 theCriteria[ i ].Type = FT_BelongToGeom;
1266 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1267 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1271 case FT_BelongToPlane:
1272 case FT_BelongToCylinder:
1274 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
1276 CORBA::ULong i = theCriteria->length();
1277 theCriteria->length( i + 1 );
1279 theCriteria[ i ] = createCriterion();
1281 theCriteria[ i ].Type = aFType;
1282 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1283 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1284 theCriteria[ i ].Tolerance = aPred->GetTolerance();
1290 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
1292 CORBA::ULong i = theCriteria->length();
1293 theCriteria->length( i + 1 );
1295 theCriteria[ i ] = createCriterion();
1297 theCriteria[ i ].Type = FT_RangeOfIds;
1298 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
1299 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1307 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
1309 CORBA::ULong i = theCriteria->length();
1310 theCriteria->length( i + 1 );
1312 theCriteria[ i ] = createCriterion();
1314 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
1315 theCriteria[ i ].Compare = aFType;
1316 theCriteria[ i ].Threshold = aCompar->GetMargin();
1317 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
1319 if ( aFType == FT_EqualTo )
1321 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
1322 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
1329 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
1330 getCriteria( aPred, theCriteria );
1331 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
1338 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
1339 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
1340 if ( !getCriteria( aPred1, theCriteria ) )
1342 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
1343 return getCriteria( aPred2, theCriteria );
1353 //=======================================================================
1354 // name : Filter_i::GetCriteria
1355 // Purpose : Retrieve criterions from predicate
1356 //=======================================================================
1357 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
1359 theCriteria = new SMESH::Filter::Criteria;
1360 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
1363 //=======================================================================
1364 // name : Filter_i::SetCriteria
1365 // Purpose : Create new predicate and set criterions in it
1366 //=======================================================================
1367 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
1369 if ( myPredicate != 0 )
1370 myPredicate->Destroy();
1372 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1373 FilterManager_ptr aFilterMgr = aFilter->_this();
1375 // CREATE two lists ( PREDICATES and LOG OP )
1378 std::list<SMESH::Predicate_ptr> aPredicates;
1379 std::list<int> aBinaries;
1380 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
1382 int aCriterion = theCriteria[ i ].Type;
1383 int aCompare = theCriteria[ i ].Compare;
1384 double aThreshold = theCriteria[ i ].Threshold;
1385 int aUnary = theCriteria[ i ].UnaryOp;
1386 int aBinary = theCriteria[ i ].BinaryOp;
1387 double aTolerance = theCriteria[ i ].Tolerance;
1388 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
1389 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
1390 long aPrecision = theCriteria[ i ].Precision;
1392 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
1393 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
1395 switch ( aCriterion )
1399 case SMESH::FT_MultiConnection:
1400 aFunctor = aFilterMgr->CreateMultiConnection();
1402 case SMESH::FT_Length:
1403 aFunctor = aFilterMgr->CreateLength();
1405 case SMESH::FT_AspectRatio:
1406 aFunctor = aFilterMgr->CreateAspectRatio();
1408 case SMESH::FT_Warping:
1409 aFunctor = aFilterMgr->CreateWarping();
1411 case SMESH::FT_MinimumAngle:
1412 aFunctor = aFilterMgr->CreateMinimumAngle();
1414 case SMESH::FT_Taper:
1415 aFunctor = aFilterMgr->CreateTaper();
1417 case SMESH::FT_Skew:
1418 aFunctor = aFilterMgr->CreateSkew();
1420 case SMESH::FT_Area:
1421 aFunctor = aFilterMgr->CreateArea();
1426 case SMESH::FT_FreeBorders:
1427 aPredicate = aFilterMgr->CreateFreeBorders();
1429 case SMESH::FT_FreeEdges:
1430 aPredicate = aFilterMgr->CreateFreeEdges();
1432 case SMESH::FT_BelongToGeom:
1434 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
1435 tmpPred->SetElementType( aTypeOfElem );
1436 tmpPred->SetShapeName( aThresholdStr );
1437 aPredicate = tmpPred;
1440 case SMESH::FT_BelongToPlane:
1441 case SMESH::FT_BelongToCylinder:
1443 SMESH::BelongToSurface_ptr tmpPred;
1444 if ( aCriterion == SMESH::FT_BelongToPlane )
1445 tmpPred = aFilterMgr->CreateBelongToPlane();
1447 tmpPred = aFilterMgr->CreateBelongToCylinder();
1448 tmpPred->SetShapeName( aThresholdStr, aTypeOfElem );
1449 tmpPred->SetTolerance( aTolerance );
1450 aPredicate = tmpPred;
1453 case SMESH::FT_RangeOfIds:
1455 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
1456 tmpPred->SetRangeStr( aThresholdStr );
1457 tmpPred->SetElementType( aTypeOfElem );
1458 aPredicate = tmpPred;
1467 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
1469 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
1471 if ( aCompare == SMESH::FT_LessThan )
1472 aComparator = aFilterMgr->CreateLessThan();
1473 else if ( aCompare == SMESH::FT_MoreThan )
1474 aComparator = aFilterMgr->CreateMoreThan();
1475 else if ( aCompare == SMESH::FT_EqualTo )
1476 aComparator = aFilterMgr->CreateEqualTo();
1480 aComparator->SetNumFunctor( aFunctor );
1481 aComparator->SetMargin( aThreshold );
1483 if ( aCompare == FT_EqualTo )
1485 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
1486 anEqualTo->SetTolerance( aTolerance );
1489 aPredicate = aComparator;
1491 aFunctor->SetPrecision( aPrecision );
1495 if ( aUnary == FT_LogicalNOT )
1497 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
1498 aNotPred->SetPredicate( aPredicate );
1499 aPredicate = aNotPred;
1503 aPredicates.push_back( aPredicate );
1504 aBinaries.push_back( aBinary );
1508 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
1510 // combine all "AND" operations
1512 std::list<SMESH::Predicate_ptr> aResList;
1514 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
1515 std::list<int>::iterator aBinaryIter;
1517 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
1518 int aPrevBinary = SMESH::FT_Undefined;
1520 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
1521 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
1522 ++aPredIter, ++aBinaryIter )
1524 int aCurrBinary = *aBinaryIter;
1526 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
1528 if ( aPrevBinary == SMESH::FT_LogicalAND )
1531 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
1532 aBinaryPred->SetPredicate1( aPrevPredicate );
1533 aBinaryPred->SetPredicate2( *aPredIter );
1534 aCurrPred = aBinaryPred;
1537 aCurrPred = *aPredIter;
1539 if ( aCurrBinary != SMESH::FT_LogicalAND )
1540 aResList.push_back( aCurrPred );
1542 aPrevPredicate = aCurrPred;
1543 aPrevBinary = aCurrBinary;
1546 // combine all "OR" operations
1548 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
1550 if ( aResList.size() == 1 )
1551 aResPredicate = *aResList.begin();
1552 else if ( aResList.size() > 1 )
1554 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
1555 aResPredicate = *anIter;
1557 for ( ; anIter != aResList.end(); ++anIter )
1559 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
1560 aBinaryPred->SetPredicate1( aResPredicate );
1561 aBinaryPred->SetPredicate2( *anIter );
1562 aResPredicate = aBinaryPred;
1566 SetPredicate( aResPredicate );
1568 return !aResPredicate->_is_nil();
1571 //=======================================================================
1572 // name : Filter_i::GetPredicate_i
1573 // Purpose : Get implementation of predicate
1574 //=======================================================================
1575 Predicate_i* Filter_i::GetPredicate_i()
1580 //=======================================================================
1581 // name : Filter_i::GetPredicate
1582 // Purpose : Get predicate
1583 //=======================================================================
1584 Predicate_ptr Filter_i::GetPredicate()
1586 if ( myPredicate == 0 )
1587 return SMESH::Predicate::_nil();
1590 SMESH::Predicate_var anObj = myPredicate->_this();
1591 return anObj._retn();
1599 #define ATTR_TYPE "type"
1600 #define ATTR_COMPARE "compare"
1601 #define ATTR_THRESHOLD "threshold"
1602 #define ATTR_UNARY "unary"
1603 #define ATTR_BINARY "binary"
1604 #define ATTR_THRESHOLD_STR "threshold_str"
1605 #define ATTR_TOLERANCE "tolerance"
1606 #define ATTR_ELEMENT_TYPE "ElementType"
1608 //=======================================================================
1610 // Purpose : Convert bool to LDOMString
1611 //=======================================================================
1612 static inline LDOMString toString( const bool val )
1614 return val ? "logical not" : "";
1617 //=======================================================================
1619 // Purpose : Convert LDOMString to bool
1620 //=======================================================================
1621 static inline bool toBool( const LDOMString& theStr )
1623 return theStr.equals( "logical not" );
1626 //=======================================================================
1628 // Purpose : Convert double to LDOMString
1629 //=======================================================================
1630 static inline LDOMString toString( const double val )
1633 sprintf( a, "%e", val );
1634 return LDOMString( a );
1637 //=======================================================================
1639 // Purpose : Convert LDOMString to double
1640 //=======================================================================
1641 static inline double toDouble( const LDOMString& theStr )
1643 return atof( theStr.GetString() );
1646 //=======================================================================
1648 // Purpose : Convert functor type to LDOMString
1649 //=======================================================================
1650 static inline LDOMString toString( const long theType )
1654 case FT_AspectRatio : return "Aspect ratio";
1655 case FT_Warping : return "Warping";
1656 case FT_MinimumAngle : return "Minimum angle";
1657 case FT_Taper : return "Taper";
1658 case FT_Skew : return "Skew";
1659 case FT_Area : return "Area";
1660 case FT_BelongToGeom : return "Belong to Geom";
1661 case FT_BelongToPlane : return "Belong to Plane";
1662 case FT_BelongToCylinder: return "Belong to Cylinder";
1663 case FT_RangeOfIds : return "Range of IDs";
1664 case FT_FreeBorders : return "Free borders";
1665 case FT_FreeEdges : return "Free edges";
1666 case FT_MultiConnection : return "Borders at multi-connections";
1667 case FT_Length : return "Length";
1668 case FT_LessThan : return "Less than";
1669 case FT_MoreThan : return "More than";
1670 case FT_EqualTo : return "Equal to";
1671 case FT_LogicalNOT : return "Not";
1672 case FT_LogicalAND : return "And";
1673 case FT_LogicalOR : return "Or";
1674 case FT_Undefined : return "";
1675 default : return "";
1679 //=======================================================================
1680 // name : toFunctorType
1681 // Purpose : Convert LDOMString to functor type
1682 //=======================================================================
1683 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
1685 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
1686 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
1687 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
1688 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
1689 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
1690 else if ( theStr.equals( "Area" ) ) return FT_Area;
1691 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
1692 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
1693 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
1694 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
1695 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
1696 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
1697 else if ( theStr.equals( "Length" ) ) return FT_Length;
1698 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
1699 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
1700 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
1701 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
1702 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
1703 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
1704 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
1705 else if ( theStr.equals( "" ) ) return FT_Undefined;
1706 else return FT_Undefined;
1709 //=======================================================================
1710 // name : toFunctorType
1711 // Purpose : Convert LDOMString to value of ElementType enumeration
1712 //=======================================================================
1713 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
1715 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
1716 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
1717 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
1718 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
1719 else return SMESH::ALL;
1722 //=======================================================================
1724 // Purpose : Convert ElementType to string
1725 //=======================================================================
1726 static inline LDOMString toString( const SMESH::ElementType theType )
1730 case SMESH::NODE : return "NODE";
1731 case SMESH::EDGE : return "EDGE";
1732 case SMESH::FACE : return "FACE";
1733 case SMESH::VOLUME : return "VOLUME";
1734 case SMESH::ALL : return "ALL";
1735 default : return "";
1739 //=======================================================================
1740 // name : findFilter
1741 // Purpose : Find filter in document
1742 //=======================================================================
1743 static LDOM_Element findFilter( const char* theFilterName,
1744 const LDOM_Document& theDoc,
1745 LDOM_Node* theParent = 0 )
1747 LDOM_Element aRootElement = theDoc.getDocumentElement();
1748 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
1749 return LDOM_Element();
1751 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
1752 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
1754 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
1755 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
1757 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
1758 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
1759 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
1761 if ( theParent != 0 )
1762 *theParent = aTypeNode;
1763 return (LDOM_Element&)aFilter;
1767 return LDOM_Element();
1770 //=======================================================================
1771 // name : getSectionName
1772 // Purpose : Get name of section of filters
1773 //=======================================================================
1774 static const char* getSectionName( const ElementType theType )
1778 case SMESH::NODE : return "Filters for nodes";
1779 case SMESH::EDGE : return "Filters for edges";
1780 case SMESH::FACE : return "Filters for faces";
1781 case SMESH::VOLUME : return "Filters for volumes";
1782 case SMESH::ALL : return "Filters for elements";
1783 default : return "";
1787 //=======================================================================
1788 // name : getSection
1789 // Purpose : Create section for filters corresponding to the entity type
1790 //=======================================================================
1791 static LDOM_Node getSection( const ElementType theType,
1792 LDOM_Document& theDoc,
1793 const bool toCreate = false )
1795 LDOM_Element aRootElement = theDoc.getDocumentElement();
1796 if ( aRootElement.isNull() )
1800 bool anExist = false;
1801 const char* aSectionName = getSectionName( theType );
1802 if ( strcmp( aSectionName, "" ) == 0 )
1805 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
1807 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
1809 aNode = aSections.item( i );
1810 LDOM_Element& anItem = ( LDOM_Element& )aNode;
1811 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
1818 // Create new section if necessary
1823 LDOM_Element aNewItem = theDoc.createElement( "section" );
1824 aNewItem.setAttribute( "name", aSectionName );
1825 aRootElement.appendChild( aNewItem );
1835 //=======================================================================
1836 // name : createFilterItem
1837 // Purpose : Create filter item or LDOM document
1838 //=======================================================================
1839 static LDOM_Element createFilterItem( const char* theName,
1840 SMESH::Filter_ptr theFilter,
1841 LDOM_Document& theDoc )
1843 // create new filter in document
1844 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
1845 aFilterItem.setAttribute( "name", theName );
1847 // save filter criterions
1848 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
1850 if ( !theFilter->GetCriteria( aCriteria ) )
1851 return LDOM_Element();
1853 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
1855 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
1857 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type ) );
1858 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
1859 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
1860 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
1861 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
1863 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
1864 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
1865 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
1866 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
1868 aFilterItem.appendChild( aCriterionItem );
1874 //=======================================================================
1875 // name : FilterLibrary_i::FilterLibrary_i
1876 // Purpose : Constructor
1877 //=======================================================================
1878 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
1880 myFileName = strdup( theFileName );
1881 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
1882 myFilterMgr = aFilterMgr->_this();
1886 // Try to use existing library file
1887 bool anExists = false;
1888 if ( !aParser.parse( myFileName ) )
1890 myDoc = aParser.getDocument();
1893 // Create a new XML document if it doesn't exist
1895 myDoc = LDOM_Document::createDocument( LDOMString() );
1897 LDOM_Element aRootElement = myDoc.getDocumentElement();
1898 if ( aRootElement.isNull() )
1900 // If the existing document is empty --> try to create a new one
1902 myDoc = LDOM_Document::createDocument( LDOMString() );
1906 //=======================================================================
1907 // name : FilterLibrary_i::FilterLibrary_i
1908 // Purpose : Constructor
1909 //=======================================================================
1910 FilterLibrary_i::FilterLibrary_i()
1913 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1914 myFilterMgr = aFilter->_this();
1916 myDoc = LDOM_Document::createDocument( LDOMString() );
1919 FilterLibrary_i::~FilterLibrary_i()
1924 //=======================================================================
1925 // name : FilterLibrary_i::Copy
1926 // Purpose : Create filter and initialize it with values from library
1927 //=======================================================================
1928 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
1931 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
1933 if ( aFilter.isNull() )
1936 std::list<SMESH::Filter::Criterion> aCriteria;
1938 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
1939 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
1941 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
1943 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
1944 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
1945 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
1946 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
1947 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
1949 SMESH::Filter::Criterion aCriterion = createCriterion();
1951 aCriterion.Type = toFunctorType( aTypeStr );
1952 aCriterion.Compare = toFunctorType( aCompareStr );
1953 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
1954 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
1956 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
1958 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
1960 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
1961 ? val : atof( str.GetString() );
1963 str = aCrit->getAttribute( ATTR_TOLERANCE );
1964 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
1965 ? val : atof( str.GetString() );
1967 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
1968 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
1971 sprintf( a, "%d", val );
1972 aCriterion.ThresholdStr = strdup( a );
1975 aCriterion.ThresholdStr = str.GetString();
1977 aCriteria.push_back( aCriterion );
1980 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
1981 aCriteriaVar->length( aCriteria.size() );
1984 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
1986 for( ; anIter != aCriteria.end(); ++anIter )
1987 aCriteriaVar[ i++ ] = *anIter;
1989 aRes = myFilterMgr->CreateFilter();
1990 aRes->SetCriteria( aCriteriaVar.inout() );
1995 //=======================================================================
1996 // name : FilterLibrary_i::SetFileName
1997 // Purpose : Set file name for library
1998 //=======================================================================
1999 void FilterLibrary_i::SetFileName( const char* theFileName )
2002 myFileName = strdup( theFileName );
2005 //=======================================================================
2006 // name : FilterLibrary_i::GetFileName
2007 // Purpose : Get file name of library
2008 //=======================================================================
2009 char* FilterLibrary_i::GetFileName()
2011 return CORBA::string_dup( myFileName );
2014 //=======================================================================
2015 // name : FilterLibrary_i::Add
2016 // Purpose : Add new filter to library
2017 //=======================================================================
2018 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
2020 // if filter already in library or entry filter is null do nothing
2021 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2022 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
2025 // get section corresponding to the filter type
2026 ElementType anEntType = theFilter->GetElementType();
2028 LDOM_Node aSection = getSection( anEntType, myDoc, true );
2029 if ( aSection.isNull() )
2032 // create filter item
2033 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
2034 if ( aFilterItem.isNull() )
2038 aSection.appendChild( aFilterItem );
2043 //=======================================================================
2044 // name : FilterLibrary_i::Add
2045 // Purpose : Add new filter to library
2046 //=======================================================================
2047 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
2049 // if filter already in library or entry filter is null do nothing
2050 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2051 if ( !aFilterNode.isNull() )
2054 LDOM_Node aSection = getSection( theType, myDoc, true );
2055 if ( aSection.isNull() )
2058 // create filter item
2059 Filter_var aFilter = myFilterMgr->CreateFilter();
2061 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
2062 if ( aFilterItem.isNull() )
2066 aSection.appendChild( aFilterItem );
2071 //=======================================================================
2072 // name : FilterLibrary_i::Delete
2073 // Purpose : Delete filter from library
2074 //=======================================================================
2075 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
2077 LDOM_Node aParentNode;
2078 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
2079 if ( aFilterNode.isNull() || aParentNode.isNull() )
2082 aParentNode.removeChild( aFilterNode );
2086 //=======================================================================
2087 // name : FilterLibrary_i::Replace
2088 // Purpose : Replace existing filter with entry filter.
2089 // IMPORTANT : If filter does not exist it is not created
2090 //=======================================================================
2091 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
2092 const char* theNewName,
2093 Filter_ptr theFilter )
2095 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
2096 if ( aFilterItem.isNull() || theFilter->_is_nil() )
2099 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
2100 if ( aNewItem.isNull() )
2104 aFilterItem.ReplaceElement( aNewItem );
2109 //=======================================================================
2110 // name : FilterLibrary_i::Save
2111 // Purpose : Save library on disk
2112 //=======================================================================
2113 CORBA::Boolean FilterLibrary_i::Save()
2115 if ( myFileName == 0 || strlen( myFileName ) == 0 )
2118 FILE* aOutFile = fopen( myFileName, "wt" );
2122 LDOM_XmlWriter aWriter( aOutFile );
2123 aWriter.SetIndentation( 2 );
2130 //=======================================================================
2131 // name : FilterLibrary_i::SaveAs
2132 // Purpose : Save library on disk
2133 //=======================================================================
2134 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
2136 myFileName = strdup ( aFileName );
2140 //=======================================================================
2141 // name : FilterLibrary_i::IsPresent
2142 // Purpose : Verify whether filter is in library
2143 //=======================================================================
2144 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
2146 return !findFilter( theFilterName, myDoc ).isNull();
2149 //=======================================================================
2150 // name : FilterLibrary_i::NbFilters
2151 // Purpose : Return amount of filters in library
2152 //=======================================================================
2153 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
2155 string_array_var aNames = GetNames( theType );
2156 return aNames->length();
2159 //=======================================================================
2160 // name : FilterLibrary_i::GetNames
2161 // Purpose : Get names of filters from library
2162 //=======================================================================
2163 string_array* FilterLibrary_i::GetNames( ElementType theType )
2165 string_array_var anArray = new string_array;
2166 TColStd_SequenceOfHAsciiString aSeq;
2168 LDOM_Node aSection = getSection( theType, myDoc, false );
2170 if ( !aSection.isNull() )
2172 for ( LDOM_Node aFilter = aSection.getFirstChild();
2173 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2175 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
2176 aSeq.Append( new TCollection_HAsciiString(
2177 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
2181 anArray->length( aSeq.Length() );
2182 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
2183 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
2185 return anArray._retn();
2188 //=======================================================================
2189 // name : FilterLibrary_i::GetAllNames
2190 // Purpose : Get names of filters from library
2191 //=======================================================================
2192 string_array* FilterLibrary_i::GetAllNames()
2194 string_array_var aResArray = new string_array;
2195 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
2197 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
2199 int aPrevLength = aResArray->length();
2200 aResArray->length( aPrevLength + aNames->length() );
2201 for ( int i = 0, n = aNames->length(); i < n; i++ )
2202 aResArray[ aPrevLength + i ] = aNames[ i ];
2205 return aResArray._retn();