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;
494 Description : Base class for all predicates
496 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
498 return myPredicatePtr->IsSatisfy( theId );
501 Controls::PredicatePtr Predicate_i::GetPredicate()
503 return myPredicatePtr;
508 Class : BelongToGeom_i
509 Description : Predicate for selection on geometrical support
511 BelongToGeom_i::BelongToGeom_i()
513 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
514 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
518 BelongToGeom_i::~BelongToGeom_i()
523 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
525 if ( theGeom->_is_nil() )
527 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
528 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
529 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
530 myBelongToGeomPtr->SetGeom( aLocShape );
533 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
535 myBelongToGeomPtr->SetGeom( theShape );
538 void BelongToGeom_i::SetElementType(ElementType theType){
539 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
542 FunctorType BelongToGeom_i::GetFunctorType()
544 return SMESH::FT_BelongToGeom;
547 void BelongToGeom_i::SetShapeName( const char* theName )
550 myShapeName = strdup( theName );
551 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
554 char* BelongToGeom_i::GetShapeName()
556 return CORBA::string_dup( myShapeName );
560 Class : BelongToSurface_i
561 Description : Predicate for selection on geometrical support
563 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
565 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
566 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
568 mySurfaceType = theSurfaceType;
571 BelongToSurface_i::~BelongToSurface_i()
576 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
578 if ( theGeom->_is_nil() )
580 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
581 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
582 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
584 if ( aLocShape.ShapeType() == TopAbs_FACE )
586 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
587 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
589 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
594 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
597 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
600 myShapeName = strdup( theName );
601 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
604 char* BelongToSurface_i::GetShapeName()
606 return CORBA::string_dup( myShapeName );
609 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
611 myElementsOnSurfacePtr->SetTolerance( theToler );
614 CORBA::Double BelongToSurface_i::GetTolerance()
616 return myElementsOnSurfacePtr->GetTolerance();
620 Class : BelongToPlane_i
621 Description : Verify whether mesh element lie in pointed Geom planar object
624 BelongToPlane_i::BelongToPlane_i()
625 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
629 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
631 BelongToSurface_i::SetSurface( theGeom, theType );
634 FunctorType BelongToPlane_i::GetFunctorType()
636 return FT_BelongToPlane;
640 Class : BelongToCylinder_i
641 Description : Verify whether mesh element lie in pointed Geom planar object
644 BelongToCylinder_i::BelongToCylinder_i()
645 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
649 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
651 BelongToSurface_i::SetSurface( theGeom, theType );
654 FunctorType BelongToCylinder_i::GetFunctorType()
656 return FT_BelongToCylinder;
662 Class : FreeBorders_i
663 Description : Predicate for free borders
665 FreeBorders_i::FreeBorders_i()
667 myPredicatePtr.reset(new Controls::FreeBorders());
668 myFunctorPtr = myPredicatePtr;
671 FunctorType FreeBorders_i::GetFunctorType()
673 return SMESH::FT_FreeBorders;
678 Description : Predicate for free borders
680 FreeEdges_i::FreeEdges_i()
681 : myFreeEdgesPtr( new Controls::FreeEdges() )
683 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
686 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
688 INFOS("FreeEdges_i::GetBorders");
689 SMESH::Controls::FreeEdges::TBorders aBorders;
690 myFreeEdgesPtr->GetBoreders( aBorders );
692 long i = 0, iEnd = aBorders.size();
694 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders(iEnd);
696 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
697 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
699 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
700 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
702 aBorder.myElemId = aBord.myElemId;
703 aBorder.myPnt1 = aBord.myPntId[ 0 ];
704 aBorder.myPnt2 = aBord.myPntId[ 1 ];
707 INFOS("FreeEdges_i::GetBorders~");
708 return aResult._retn();
711 FunctorType FreeEdges_i::GetFunctorType()
713 return SMESH::FT_FreeEdges;
718 Description : Predicate for Range of Ids.
719 Range may be specified with two ways.
720 1. Using AddToRange method
721 2. With SetRangeStr method. Parameter of this method is a string
722 like as "1,2,3,50-60,63,67,70-"
725 RangeOfIds_i::RangeOfIds_i()
727 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
728 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
731 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
733 CORBA::Long iEnd = theIds.length();
734 for ( CORBA::Long i = 0; i < iEnd; i++ )
735 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
738 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
740 return myRangeOfIdsPtr->SetRangeStr(
741 TCollection_AsciiString( (Standard_CString)theRange ) );
744 char* RangeOfIds_i::GetRangeStr()
746 TCollection_AsciiString aStr;
747 myRangeOfIdsPtr->GetRangeStr( aStr );
748 return CORBA::string_dup( aStr.ToCString() );
751 void RangeOfIds_i::SetElementType( ElementType theType )
753 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
756 FunctorType RangeOfIds_i::GetFunctorType()
758 return SMESH::FT_RangeOfIds;
763 Description : Base class for comparators
765 Comparator_i::Comparator_i():
766 myNumericalFunctor( NULL )
769 Comparator_i::~Comparator_i()
771 if ( myNumericalFunctor )
772 myNumericalFunctor->Destroy();
775 void Comparator_i::SetMargin( CORBA::Double theValue )
777 myComparatorPtr->SetMargin( theValue );
780 CORBA::Double Comparator_i::GetMargin()
782 return myComparatorPtr->GetMargin();
785 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
787 if ( myNumericalFunctor )
788 myNumericalFunctor->Destroy();
790 myNumericalFunctor = dynamic_cast<NumericalFunctor_i*>( SMESH_Gen_i::GetServant( theFunct ).in() );
792 if ( myNumericalFunctor )
794 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
795 myNumericalFunctor->Register();
799 Controls::ComparatorPtr Comparator_i::GetComparator()
801 return myComparatorPtr;
804 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
806 return myNumericalFunctor;
812 Description : Comparator "<"
814 LessThan_i::LessThan_i()
816 myComparatorPtr.reset( new Controls::LessThan() );
817 myFunctorPtr = myPredicatePtr = myComparatorPtr;
820 FunctorType LessThan_i::GetFunctorType()
822 return SMESH::FT_LessThan;
828 Description : Comparator ">"
830 MoreThan_i::MoreThan_i()
832 myComparatorPtr.reset( new Controls::MoreThan() );
833 myFunctorPtr = myPredicatePtr = myComparatorPtr;
836 FunctorType MoreThan_i::GetFunctorType()
838 return SMESH::FT_MoreThan;
844 Description : Comparator "="
846 EqualTo_i::EqualTo_i()
847 : myEqualToPtr( new Controls::EqualTo() )
849 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
852 void EqualTo_i::SetTolerance( CORBA::Double theToler )
854 myEqualToPtr->SetTolerance( theToler );
857 CORBA::Double EqualTo_i::GetTolerance()
859 return myEqualToPtr->GetTolerance();
862 FunctorType EqualTo_i::GetFunctorType()
864 return SMESH::FT_EqualTo;
869 Description : Logical NOT predicate
871 LogicalNOT_i::LogicalNOT_i()
872 : myPredicate( NULL ),
873 myLogicalNOTPtr( new Controls::LogicalNOT() )
875 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
878 LogicalNOT_i::~LogicalNOT_i()
881 myPredicate->Destroy();
884 void LogicalNOT_i::SetPredicate( Predicate_ptr thePred )
887 myPredicate->Destroy();
889 myPredicate = dynamic_cast<Predicate_i*>( SMESH_Gen_i::GetServant( thePred ).in() );
892 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
893 myPredicate->Register();
897 FunctorType LogicalNOT_i::GetFunctorType()
899 return SMESH::FT_LogicalNOT;
902 Predicate_i* LogicalNOT_i::GetPredicate_i()
909 Class : LogicalBinary_i
910 Description : Base class for binary logical predicate
912 LogicalBinary_i::LogicalBinary_i()
913 : myPredicate1( NULL ),
917 LogicalBinary_i::~LogicalBinary_i()
920 myPredicate1->Destroy();
923 myPredicate2->Destroy();
926 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
929 myPredicate1->SetMesh( theMesh );
932 myPredicate2->SetMesh( theMesh );
935 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
938 myPredicate1->Destroy();
940 myPredicate1 = dynamic_cast<Predicate_i*>( SMESH_Gen_i::GetServant( thePredicate ).in() );
943 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
944 myPredicate1->Register();
948 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
951 myPredicate2->Destroy();
953 myPredicate2 = dynamic_cast<Predicate_i*>( SMESH_Gen_i::GetServant( thePredicate ).in() );
956 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
957 myPredicate2->Register();
961 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
963 return myLogicalBinaryPtr;
966 Predicate_i* LogicalBinary_i::GetPredicate1_i()
970 Predicate_i* LogicalBinary_i::GetPredicate2_i()
978 Description : Logical AND
980 LogicalAND_i::LogicalAND_i()
982 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
983 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
986 FunctorType LogicalAND_i::GetFunctorType()
988 return SMESH::FT_LogicalAND;
994 Description : Logical OR
996 LogicalOR_i::LogicalOR_i()
998 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
999 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1002 FunctorType LogicalOR_i::GetFunctorType()
1004 return SMESH::FT_LogicalOR;
1012 FilterManager_i::FilterManager_i()
1013 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1015 SMESH_Gen_i::GetPOA()->activate_object( this );
1018 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1020 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1021 SMESH::MinimumAngle_var anObj = aServant->_this();
1022 return anObj._retn();
1026 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1028 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1029 SMESH::AspectRatio_var anObj = aServant->_this();
1030 return anObj._retn();
1034 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1036 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1037 SMESH::AspectRatio3D_var anObj = aServant->_this();
1038 return anObj._retn();
1042 Warping_ptr FilterManager_i::CreateWarping()
1044 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1045 SMESH::Warping_var anObj = aServant->_this();
1046 return anObj._retn();
1050 Taper_ptr FilterManager_i::CreateTaper()
1052 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1053 SMESH::Taper_var anObj = aServant->_this();
1054 return anObj._retn();
1058 Skew_ptr FilterManager_i::CreateSkew()
1060 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1061 SMESH::Skew_var anObj = aServant->_this();
1062 return anObj._retn();
1066 Area_ptr FilterManager_i::CreateArea()
1068 SMESH::Area_i* aServant = new SMESH::Area_i();
1069 SMESH::Area_var anObj = aServant->_this();
1070 return anObj._retn();
1074 Length_ptr FilterManager_i::CreateLength()
1076 SMESH::Length_i* aServant = new SMESH::Length_i();
1077 SMESH::Length_var anObj = aServant->_this();
1078 return anObj._retn();
1081 Length2D_ptr FilterManager_i::CreateLength2D()
1083 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1084 SMESH::Length2D_var anObj = aServant->_this();
1085 return anObj._retn();
1088 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1090 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1091 SMESH::MultiConnection_var anObj = aServant->_this();
1092 return anObj._retn();
1096 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1098 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1099 SMESH::BelongToGeom_var anObj = aServant->_this();
1100 return anObj._retn();
1103 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1105 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1106 SMESH::BelongToPlane_var anObj = aServant->_this();
1107 return anObj._retn();
1110 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1112 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1113 SMESH::BelongToCylinder_var anObj = aServant->_this();
1114 return anObj._retn();
1117 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1119 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1120 SMESH::FreeBorders_var anObj = aServant->_this();
1121 return anObj._retn();
1124 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1126 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1127 SMESH::FreeEdges_var anObj = aServant->_this();
1128 return anObj._retn();
1131 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1133 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1134 SMESH::RangeOfIds_var anObj = aServant->_this();
1135 return anObj._retn();
1138 LessThan_ptr FilterManager_i::CreateLessThan()
1140 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1141 SMESH::LessThan_var anObj = aServant->_this();
1142 return anObj._retn();
1146 MoreThan_ptr FilterManager_i::CreateMoreThan()
1148 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1149 SMESH::MoreThan_var anObj = aServant->_this();
1150 return anObj._retn();
1153 EqualTo_ptr FilterManager_i::CreateEqualTo()
1155 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1156 SMESH::EqualTo_var anObj = aServant->_this();
1157 return anObj._retn();
1161 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1163 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1164 SMESH::LogicalNOT_var anObj = aServant->_this();
1165 return anObj._retn();
1169 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
1171 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
1172 SMESH::LogicalAND_var anObj = aServant->_this();
1173 return anObj._retn();
1177 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
1179 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
1180 SMESH::LogicalOR_var anObj = aServant->_this();
1181 return anObj._retn();
1184 Filter_ptr FilterManager_i::CreateFilter()
1186 SMESH::Filter_i* aServant = new SMESH::Filter_i();
1187 SMESH::Filter_var anObj = aServant->_this();
1188 return anObj._retn();
1191 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
1193 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
1194 SMESH::FilterLibrary_var anObj = aServant->_this();
1195 return anObj._retn();
1198 FilterLibrary_ptr FilterManager_i::CreateLibrary()
1200 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
1201 SMESH::FilterLibrary_var anObj = aServant->_this();
1202 return anObj._retn();
1205 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
1207 return remove( aFileName ) ? false : true;
1210 //=============================================================================
1212 * SMESH_Gen_i::CreateFilterManager
1214 * Create filter manager
1216 //=============================================================================
1218 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
1220 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1221 SMESH::FilterManager_var anObj = aFilter->_this();
1222 return anObj._retn();
1230 //=======================================================================
1231 // name : Filter_i::Filter_i
1232 // Purpose : Constructor
1233 //=======================================================================
1234 Filter_i::Filter_i()
1235 : myPredicate( NULL )
1238 //=======================================================================
1239 // name : Filter_i::~Filter_i
1240 // Purpose : Destructor
1241 //=======================================================================
1242 Filter_i::~Filter_i()
1245 myPredicate->Destroy();
1248 //=======================================================================
1249 // name : Filter_i::SetPredicate
1250 // Purpose : Set predicate
1251 //=======================================================================
1252 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
1255 myPredicate->Destroy();
1257 myPredicate = dynamic_cast<Predicate_i*>( SMESH_Gen_i::GetServant( thePredicate ).in() );
1261 myFilter.SetPredicate( myPredicate->GetPredicate() );
1262 myPredicate->Register();
1266 //=======================================================================
1267 // name : Filter_i::GetElementType
1268 // Purpose : Get entity type
1269 //=======================================================================
1270 SMESH::ElementType Filter_i::GetElementType()
1272 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
1275 //=======================================================================
1276 // name : Filter_i::SetMesh
1277 // Purpose : Set mesh
1278 //=======================================================================
1279 void Filter_i::SetMesh( SMESH_Mesh_ptr theMesh )
1282 myPredicate->SetMesh( theMesh );
1285 //=======================================================================
1286 // name : Filter_i::GetElementsId
1287 // Purpose : Get ids of entities
1288 //=======================================================================
1289 SMESH::long_array* Filter_i::GetElementsId( SMESH_Mesh_ptr theMesh )
1291 SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh);
1292 Controls::Filter::TIdSequence aSequence = myFilter.GetElementsId(aMesh);
1294 SMESH::long_array_var anArray = new SMESH::long_array;
1295 long i = 0, iEnd = aSequence.size();
1297 anArray->length( iEnd );
1298 for ( ; i < iEnd; i++ )
1299 anArray[ i ] = aSequence[i];
1301 return anArray._retn();
1304 //=======================================================================
1305 // name : getCriteria
1306 // Purpose : Retrieve criterions from predicate
1307 //=======================================================================
1308 static inline bool getCriteria( Predicate_i* thePred,
1309 SMESH::Filter::Criteria_out theCriteria )
1311 int aFType = thePred->GetFunctorType();
1315 case FT_FreeBorders:
1318 CORBA::ULong i = theCriteria->length();
1319 theCriteria->length( i + 1 );
1321 theCriteria[ i ] = createCriterion();
1323 theCriteria[ i ].Type = aFType;
1324 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
1327 case FT_BelongToGeom:
1329 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
1331 CORBA::ULong i = theCriteria->length();
1332 theCriteria->length( i + 1 );
1334 theCriteria[ i ] = createCriterion();
1336 theCriteria[ i ].Type = FT_BelongToGeom;
1337 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1338 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1342 case FT_BelongToPlane:
1343 case FT_BelongToCylinder:
1345 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
1347 CORBA::ULong i = theCriteria->length();
1348 theCriteria->length( i + 1 );
1350 theCriteria[ i ] = createCriterion();
1352 theCriteria[ i ].Type = aFType;
1353 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1354 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1355 theCriteria[ i ].Tolerance = aPred->GetTolerance();
1361 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
1363 CORBA::ULong i = theCriteria->length();
1364 theCriteria->length( i + 1 );
1366 theCriteria[ i ] = createCriterion();
1368 theCriteria[ i ].Type = FT_RangeOfIds;
1369 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
1370 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1378 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
1380 CORBA::ULong i = theCriteria->length();
1381 theCriteria->length( i + 1 );
1383 theCriteria[ i ] = createCriterion();
1385 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
1386 theCriteria[ i ].Compare = aFType;
1387 theCriteria[ i ].Threshold = aCompar->GetMargin();
1388 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
1390 if ( aFType == FT_EqualTo )
1392 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
1393 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
1400 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
1401 getCriteria( aPred, theCriteria );
1402 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
1409 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
1410 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
1411 if ( !getCriteria( aPred1, theCriteria ) )
1413 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
1414 return getCriteria( aPred2, theCriteria );
1424 //=======================================================================
1425 // name : Filter_i::GetCriteria
1426 // Purpose : Retrieve criterions from predicate
1427 //=======================================================================
1428 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
1430 theCriteria = new SMESH::Filter::Criteria;
1431 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
1434 //=======================================================================
1435 // name : Filter_i::SetCriteria
1436 // Purpose : Create new predicate and set criterions in it
1437 //=======================================================================
1438 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
1440 if ( myPredicate != 0 )
1441 myPredicate->Destroy();
1443 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1444 FilterManager_ptr aFilterMgr = aFilter->_this();
1446 // CREATE two lists ( PREDICATES and LOG OP )
1449 std::list<SMESH::Predicate_ptr> aPredicates;
1450 std::list<int> aBinaries;
1451 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
1453 int aCriterion = theCriteria[ i ].Type;
1454 int aCompare = theCriteria[ i ].Compare;
1455 double aThreshold = theCriteria[ i ].Threshold;
1456 int aUnary = theCriteria[ i ].UnaryOp;
1457 int aBinary = theCriteria[ i ].BinaryOp;
1458 double aTolerance = theCriteria[ i ].Tolerance;
1459 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
1460 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
1461 long aPrecision = theCriteria[ i ].Precision;
1463 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
1464 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
1466 switch ( aCriterion )
1470 case SMESH::FT_MultiConnection:
1471 aFunctor = aFilterMgr->CreateMultiConnection();
1473 case SMESH::FT_Length:
1474 aFunctor = aFilterMgr->CreateLength();
1476 case SMESH::FT_Length2D:
1477 aFunctor = aFilterMgr->CreateLength2D();
1479 case SMESH::FT_AspectRatio:
1480 aFunctor = aFilterMgr->CreateAspectRatio();
1482 case SMESH::FT_AspectRatio3D:
1483 aFunctor = aFilterMgr->CreateAspectRatio3D();
1485 case SMESH::FT_Warping:
1486 aFunctor = aFilterMgr->CreateWarping();
1488 case SMESH::FT_MinimumAngle:
1489 aFunctor = aFilterMgr->CreateMinimumAngle();
1491 case SMESH::FT_Taper:
1492 aFunctor = aFilterMgr->CreateTaper();
1494 case SMESH::FT_Skew:
1495 aFunctor = aFilterMgr->CreateSkew();
1497 case SMESH::FT_Area:
1498 aFunctor = aFilterMgr->CreateArea();
1503 case SMESH::FT_FreeBorders:
1504 aPredicate = aFilterMgr->CreateFreeBorders();
1506 case SMESH::FT_FreeEdges:
1507 aPredicate = aFilterMgr->CreateFreeEdges();
1509 case SMESH::FT_BelongToGeom:
1511 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
1512 tmpPred->SetElementType( aTypeOfElem );
1513 tmpPred->SetShapeName( aThresholdStr );
1514 aPredicate = tmpPred;
1517 case SMESH::FT_BelongToPlane:
1518 case SMESH::FT_BelongToCylinder:
1520 SMESH::BelongToSurface_ptr tmpPred;
1521 if ( aCriterion == SMESH::FT_BelongToPlane )
1522 tmpPred = aFilterMgr->CreateBelongToPlane();
1524 tmpPred = aFilterMgr->CreateBelongToCylinder();
1525 tmpPred->SetShapeName( aThresholdStr, aTypeOfElem );
1526 tmpPred->SetTolerance( aTolerance );
1527 aPredicate = tmpPred;
1530 case SMESH::FT_RangeOfIds:
1532 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
1533 tmpPred->SetRangeStr( aThresholdStr );
1534 tmpPred->SetElementType( aTypeOfElem );
1535 aPredicate = tmpPred;
1544 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
1546 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
1548 if ( aCompare == SMESH::FT_LessThan )
1549 aComparator = aFilterMgr->CreateLessThan();
1550 else if ( aCompare == SMESH::FT_MoreThan )
1551 aComparator = aFilterMgr->CreateMoreThan();
1552 else if ( aCompare == SMESH::FT_EqualTo )
1553 aComparator = aFilterMgr->CreateEqualTo();
1557 aComparator->SetNumFunctor( aFunctor );
1558 aComparator->SetMargin( aThreshold );
1560 if ( aCompare == FT_EqualTo )
1562 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
1563 anEqualTo->SetTolerance( aTolerance );
1566 aPredicate = aComparator;
1568 aFunctor->SetPrecision( aPrecision );
1572 if ( aUnary == FT_LogicalNOT )
1574 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
1575 aNotPred->SetPredicate( aPredicate );
1576 aPredicate = aNotPred;
1580 aPredicates.push_back( aPredicate );
1581 aBinaries.push_back( aBinary );
1585 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
1587 // combine all "AND" operations
1589 std::list<SMESH::Predicate_ptr> aResList;
1591 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
1592 std::list<int>::iterator aBinaryIter;
1594 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
1595 int aPrevBinary = SMESH::FT_Undefined;
1597 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
1598 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
1599 ++aPredIter, ++aBinaryIter )
1601 int aCurrBinary = *aBinaryIter;
1603 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
1605 if ( aPrevBinary == SMESH::FT_LogicalAND )
1608 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
1609 aBinaryPred->SetPredicate1( aPrevPredicate );
1610 aBinaryPred->SetPredicate2( *aPredIter );
1611 aCurrPred = aBinaryPred;
1614 aCurrPred = *aPredIter;
1616 if ( aCurrBinary != SMESH::FT_LogicalAND )
1617 aResList.push_back( aCurrPred );
1619 aPrevPredicate = aCurrPred;
1620 aPrevBinary = aCurrBinary;
1623 // combine all "OR" operations
1625 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
1627 if ( aResList.size() == 1 )
1628 aResPredicate = *aResList.begin();
1629 else if ( aResList.size() > 1 )
1631 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
1632 aResPredicate = *anIter;
1634 for ( ; anIter != aResList.end(); ++anIter )
1636 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
1637 aBinaryPred->SetPredicate1( aResPredicate );
1638 aBinaryPred->SetPredicate2( *anIter );
1639 aResPredicate = aBinaryPred;
1643 SetPredicate( aResPredicate );
1645 return !aResPredicate->_is_nil();
1648 //=======================================================================
1649 // name : Filter_i::GetPredicate_i
1650 // Purpose : Get implementation of predicate
1651 //=======================================================================
1652 Predicate_i* Filter_i::GetPredicate_i()
1657 //=======================================================================
1658 // name : Filter_i::GetPredicate
1659 // Purpose : Get predicate
1660 //=======================================================================
1661 Predicate_ptr Filter_i::GetPredicate()
1663 if ( myPredicate == 0 )
1664 return SMESH::Predicate::_nil();
1667 SMESH::Predicate_var anObj = myPredicate->_this();
1668 return anObj._retn();
1676 #define ATTR_TYPE "type"
1677 #define ATTR_COMPARE "compare"
1678 #define ATTR_THRESHOLD "threshold"
1679 #define ATTR_UNARY "unary"
1680 #define ATTR_BINARY "binary"
1681 #define ATTR_THRESHOLD_STR "threshold_str"
1682 #define ATTR_TOLERANCE "tolerance"
1683 #define ATTR_ELEMENT_TYPE "ElementType"
1685 //=======================================================================
1687 // Purpose : Convert bool to LDOMString
1688 //=======================================================================
1689 static inline LDOMString toString( const bool val )
1691 return val ? "logical not" : "";
1694 //=======================================================================
1696 // Purpose : Convert LDOMString to bool
1697 //=======================================================================
1698 static inline bool toBool( const LDOMString& theStr )
1700 return theStr.equals( "logical not" );
1703 //=======================================================================
1705 // Purpose : Convert double to LDOMString
1706 //=======================================================================
1707 static inline LDOMString toString( const double val )
1710 sprintf( a, "%e", val );
1711 return LDOMString( a );
1714 //=======================================================================
1716 // Purpose : Convert LDOMString to double
1717 //=======================================================================
1718 static inline double toDouble( const LDOMString& theStr )
1720 return atof( theStr.GetString() );
1723 //=======================================================================
1725 // Purpose : Convert functor type to LDOMString
1726 //=======================================================================
1727 static inline LDOMString toString( const long theType )
1731 case FT_AspectRatio : return "Aspect ratio";
1732 case FT_Warping : return "Warping";
1733 case FT_MinimumAngle : return "Minimum angle";
1734 case FT_Taper : return "Taper";
1735 case FT_Skew : return "Skew";
1736 case FT_Area : return "Area";
1737 case FT_BelongToGeom : return "Belong to Geom";
1738 case FT_BelongToPlane : return "Belong to Plane";
1739 case FT_BelongToCylinder: return "Belong to Cylinder";
1740 case FT_RangeOfIds : return "Range of IDs";
1741 case FT_FreeBorders : return "Free borders";
1742 case FT_FreeEdges : return "Free edges";
1743 case FT_MultiConnection : return "Borders at multi-connections";
1744 case FT_Length : return "Length";
1745 case FT_Length2D : return "Length2D";
1746 case FT_LessThan : return "Less than";
1747 case FT_MoreThan : return "More than";
1748 case FT_EqualTo : return "Equal to";
1749 case FT_LogicalNOT : return "Not";
1750 case FT_LogicalAND : return "And";
1751 case FT_LogicalOR : return "Or";
1752 case FT_Undefined : return "";
1753 default : return "";
1757 //=======================================================================
1758 // name : toFunctorType
1759 // Purpose : Convert LDOMString to functor type
1760 //=======================================================================
1761 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
1763 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
1764 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
1765 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
1766 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
1767 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
1768 else if ( theStr.equals( "Area" ) ) return FT_Area;
1769 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
1770 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
1771 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
1772 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
1773 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
1774 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
1775 else if ( theStr.equals( "Length" ) ) return FT_Length;
1776 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
1777 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
1778 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
1779 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
1780 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
1781 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
1782 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
1783 else if ( theStr.equals( "" ) ) return FT_Undefined;
1784 else return FT_Undefined;
1787 //=======================================================================
1788 // name : toFunctorType
1789 // Purpose : Convert LDOMString to value of ElementType enumeration
1790 //=======================================================================
1791 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
1793 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
1794 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
1795 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
1796 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
1797 else return SMESH::ALL;
1800 //=======================================================================
1802 // Purpose : Convert ElementType to string
1803 //=======================================================================
1804 static inline LDOMString toString( const SMESH::ElementType theType )
1808 case SMESH::NODE : return "NODE";
1809 case SMESH::EDGE : return "EDGE";
1810 case SMESH::FACE : return "FACE";
1811 case SMESH::VOLUME : return "VOLUME";
1812 case SMESH::ALL : return "ALL";
1813 default : return "";
1817 //=======================================================================
1818 // name : findFilter
1819 // Purpose : Find filter in document
1820 //=======================================================================
1821 static LDOM_Element findFilter( const char* theFilterName,
1822 const LDOM_Document& theDoc,
1823 LDOM_Node* theParent = 0 )
1825 LDOM_Element aRootElement = theDoc.getDocumentElement();
1826 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
1827 return LDOM_Element();
1829 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
1830 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
1832 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
1833 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
1835 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
1836 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
1837 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
1839 if ( theParent != 0 )
1840 *theParent = aTypeNode;
1841 return (LDOM_Element&)aFilter;
1845 return LDOM_Element();
1848 //=======================================================================
1849 // name : getSectionName
1850 // Purpose : Get name of section of filters
1851 //=======================================================================
1852 static const char* getSectionName( const ElementType theType )
1856 case SMESH::NODE : return "Filters for nodes";
1857 case SMESH::EDGE : return "Filters for edges";
1858 case SMESH::FACE : return "Filters for faces";
1859 case SMESH::VOLUME : return "Filters for volumes";
1860 case SMESH::ALL : return "Filters for elements";
1861 default : return "";
1865 //=======================================================================
1866 // name : getSection
1867 // Purpose : Create section for filters corresponding to the entity type
1868 //=======================================================================
1869 static LDOM_Node getSection( const ElementType theType,
1870 LDOM_Document& theDoc,
1871 const bool toCreate = false )
1873 LDOM_Element aRootElement = theDoc.getDocumentElement();
1874 if ( aRootElement.isNull() )
1878 bool anExist = false;
1879 const char* aSectionName = getSectionName( theType );
1880 if ( strcmp( aSectionName, "" ) == 0 )
1883 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
1885 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
1887 aNode = aSections.item( i );
1888 LDOM_Element& anItem = ( LDOM_Element& )aNode;
1889 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
1896 // Create new section if necessary
1901 LDOM_Element aNewItem = theDoc.createElement( "section" );
1902 aNewItem.setAttribute( "name", aSectionName );
1903 aRootElement.appendChild( aNewItem );
1913 //=======================================================================
1914 // name : createFilterItem
1915 // Purpose : Create filter item or LDOM document
1916 //=======================================================================
1917 static LDOM_Element createFilterItem( const char* theName,
1918 SMESH::Filter_ptr theFilter,
1919 LDOM_Document& theDoc )
1921 // create new filter in document
1922 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
1923 aFilterItem.setAttribute( "name", theName );
1925 // save filter criterions
1926 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
1928 if ( !theFilter->GetCriteria( aCriteria ) )
1929 return LDOM_Element();
1931 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
1933 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
1935 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type ) );
1936 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
1937 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
1938 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
1939 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
1941 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
1942 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
1943 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
1944 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
1946 aFilterItem.appendChild( aCriterionItem );
1952 //=======================================================================
1953 // name : FilterLibrary_i::FilterLibrary_i
1954 // Purpose : Constructor
1955 //=======================================================================
1956 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
1958 myFileName = strdup( theFileName );
1959 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
1960 myFilterMgr = aFilterMgr->_this();
1964 // Try to use existing library file
1965 bool anExists = false;
1966 if ( !aParser.parse( myFileName ) )
1968 myDoc = aParser.getDocument();
1971 // Create a new XML document if it doesn't exist
1973 myDoc = LDOM_Document::createDocument( LDOMString() );
1975 LDOM_Element aRootElement = myDoc.getDocumentElement();
1976 if ( aRootElement.isNull() )
1978 // If the existing document is empty --> try to create a new one
1980 myDoc = LDOM_Document::createDocument( LDOMString() );
1984 //=======================================================================
1985 // name : FilterLibrary_i::FilterLibrary_i
1986 // Purpose : Constructor
1987 //=======================================================================
1988 FilterLibrary_i::FilterLibrary_i()
1991 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1992 myFilterMgr = aFilter->_this();
1994 myDoc = LDOM_Document::createDocument( LDOMString() );
1997 FilterLibrary_i::~FilterLibrary_i()
2002 //=======================================================================
2003 // name : FilterLibrary_i::Copy
2004 // Purpose : Create filter and initialize it with values from library
2005 //=======================================================================
2006 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
2009 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
2011 if ( aFilter.isNull() )
2014 std::list<SMESH::Filter::Criterion> aCriteria;
2016 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
2017 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
2019 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
2021 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
2022 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
2023 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
2024 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
2025 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
2027 SMESH::Filter::Criterion aCriterion = createCriterion();
2029 aCriterion.Type = toFunctorType( aTypeStr );
2030 aCriterion.Compare = toFunctorType( aCompareStr );
2031 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
2032 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
2034 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
2036 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
2038 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2039 ? val : atof( str.GetString() );
2041 str = aCrit->getAttribute( ATTR_TOLERANCE );
2042 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2043 ? val : atof( str.GetString() );
2045 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
2046 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
2049 sprintf( a, "%d", val );
2050 aCriterion.ThresholdStr = strdup( a );
2053 aCriterion.ThresholdStr = str.GetString();
2055 aCriteria.push_back( aCriterion );
2058 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
2059 aCriteriaVar->length( aCriteria.size() );
2062 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
2064 for( ; anIter != aCriteria.end(); ++anIter )
2065 aCriteriaVar[ i++ ] = *anIter;
2067 aRes = myFilterMgr->CreateFilter();
2068 aRes->SetCriteria( aCriteriaVar.inout() );
2073 //=======================================================================
2074 // name : FilterLibrary_i::SetFileName
2075 // Purpose : Set file name for library
2076 //=======================================================================
2077 void FilterLibrary_i::SetFileName( const char* theFileName )
2080 myFileName = strdup( theFileName );
2083 //=======================================================================
2084 // name : FilterLibrary_i::GetFileName
2085 // Purpose : Get file name of library
2086 //=======================================================================
2087 char* FilterLibrary_i::GetFileName()
2089 return CORBA::string_dup( myFileName );
2092 //=======================================================================
2093 // name : FilterLibrary_i::Add
2094 // Purpose : Add new filter to library
2095 //=======================================================================
2096 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
2098 // if filter already in library or entry filter is null do nothing
2099 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2100 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
2103 // get section corresponding to the filter type
2104 ElementType anEntType = theFilter->GetElementType();
2106 LDOM_Node aSection = getSection( anEntType, myDoc, true );
2107 if ( aSection.isNull() )
2110 // create filter item
2111 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
2112 if ( aFilterItem.isNull() )
2116 aSection.appendChild( aFilterItem );
2121 //=======================================================================
2122 // name : FilterLibrary_i::Add
2123 // Purpose : Add new filter to library
2124 //=======================================================================
2125 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
2127 // if filter already in library or entry filter is null do nothing
2128 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2129 if ( !aFilterNode.isNull() )
2132 LDOM_Node aSection = getSection( theType, myDoc, true );
2133 if ( aSection.isNull() )
2136 // create filter item
2137 Filter_var aFilter = myFilterMgr->CreateFilter();
2139 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
2140 if ( aFilterItem.isNull() )
2144 aSection.appendChild( aFilterItem );
2149 //=======================================================================
2150 // name : FilterLibrary_i::Delete
2151 // Purpose : Delete filter from library
2152 //=======================================================================
2153 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
2155 LDOM_Node aParentNode;
2156 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
2157 if ( aFilterNode.isNull() || aParentNode.isNull() )
2160 aParentNode.removeChild( aFilterNode );
2164 //=======================================================================
2165 // name : FilterLibrary_i::Replace
2166 // Purpose : Replace existing filter with entry filter.
2167 // IMPORTANT : If filter does not exist it is not created
2168 //=======================================================================
2169 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
2170 const char* theNewName,
2171 Filter_ptr theFilter )
2173 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
2174 if ( aFilterItem.isNull() || theFilter->_is_nil() )
2177 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
2178 if ( aNewItem.isNull() )
2182 aFilterItem.ReplaceElement( aNewItem );
2187 //=======================================================================
2188 // name : FilterLibrary_i::Save
2189 // Purpose : Save library on disk
2190 //=======================================================================
2191 CORBA::Boolean FilterLibrary_i::Save()
2193 if ( myFileName == 0 || strlen( myFileName ) == 0 )
2196 FILE* aOutFile = fopen( myFileName, "wt" );
2200 LDOM_XmlWriter aWriter( aOutFile );
2201 aWriter.SetIndentation( 2 );
2208 //=======================================================================
2209 // name : FilterLibrary_i::SaveAs
2210 // Purpose : Save library on disk
2211 //=======================================================================
2212 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
2214 myFileName = strdup ( aFileName );
2218 //=======================================================================
2219 // name : FilterLibrary_i::IsPresent
2220 // Purpose : Verify whether filter is in library
2221 //=======================================================================
2222 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
2224 return !findFilter( theFilterName, myDoc ).isNull();
2227 //=======================================================================
2228 // name : FilterLibrary_i::NbFilters
2229 // Purpose : Return amount of filters in library
2230 //=======================================================================
2231 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
2233 string_array_var aNames = GetNames( theType );
2234 return aNames->length();
2237 //=======================================================================
2238 // name : FilterLibrary_i::GetNames
2239 // Purpose : Get names of filters from library
2240 //=======================================================================
2241 string_array* FilterLibrary_i::GetNames( ElementType theType )
2243 string_array_var anArray = new string_array;
2244 TColStd_SequenceOfHAsciiString aSeq;
2246 LDOM_Node aSection = getSection( theType, myDoc, false );
2248 if ( !aSection.isNull() )
2250 for ( LDOM_Node aFilter = aSection.getFirstChild();
2251 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2253 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
2254 aSeq.Append( new TCollection_HAsciiString(
2255 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
2259 anArray->length( aSeq.Length() );
2260 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
2261 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
2263 return anArray._retn();
2266 //=======================================================================
2267 // name : FilterLibrary_i::GetAllNames
2268 // Purpose : Get names of filters from library
2269 //=======================================================================
2270 string_array* FilterLibrary_i::GetAllNames()
2272 string_array_var aResArray = new string_array;
2273 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
2275 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
2277 int aPrevLength = aResArray->length();
2278 aResArray->length( aPrevLength + aNames->length() );
2279 for ( int i = 0, n = aNames->length(); i < n; i++ )
2280 aResArray[ aPrevLength + i ] = aNames[ i ];
2283 return aResArray._retn();