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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Filter_i.cxx
25 // Author : Alexey Petrov, OCC
29 #include "SMESH_Filter_i.hxx"
31 #include "SMESH_Gen_i.hxx"
32 #include "SMESH_PythonDump.hxx"
34 #include "SMDS_Mesh.hxx"
35 #include "SMDS_MeshNode.hxx"
36 #include "SMDS_MeshElement.hxx"
38 #include "SMESHDS_Mesh.hxx"
40 #include <LDOM_Document.hxx>
41 #include <LDOM_Element.hxx>
42 #include <LDOM_Node.hxx>
43 #include <LDOMString.hxx>
44 #include <LDOMParser.hxx>
45 #include <LDOM_XmlWriter.hxx>
46 #include <TCollection_HAsciiString.hxx>
47 #include <TColStd_ListIteratorOfListOfInteger.hxx>
48 #include <TColStd_ListOfInteger.hxx>
49 #include <TColStd_ListOfReal.hxx>
50 #include <TColStd_MapOfInteger.hxx>
51 #include <TColStd_SequenceOfHAsciiString.hxx>
52 #include <TColStd_ListIteratorOfListOfReal.hxx>
53 #include <Precision.hxx>
54 #include <BRep_Tool.hxx>
55 #include <TopoDS_Shape.hxx>
57 #include <TopoDS_Face.hxx>
58 #include <Geom_Plane.hxx>
59 #include <Geom_CylindricalSurface.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <OSD_Path.hxx>
62 #include <OSD_File.hxx>
64 using namespace SMESH;
65 using namespace SMESH::Controls;
71 GetPredicate( Predicate_ptr thePredicate )
73 return DownCast<Predicate_i*>(thePredicate);
80 Description : Predicate for verifying whether entiy belong to
81 specified geometrical support
84 Controls::BelongToGeom::BelongToGeom()
89 void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
91 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
94 void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
99 static bool IsContains( const SMESHDS_Mesh* theMeshDS,
100 const TopoDS_Shape& theShape,
101 const SMDS_MeshElement* theElem,
102 TopAbs_ShapeEnum theFindShapeEnum,
103 TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE )
105 TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
107 while( anExp.More() )
109 const TopoDS_Shape& aShape = anExp.Current();
110 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
111 if( aSubMesh->Contains( theElem ) )
119 bool Controls::BelongToGeom::IsSatisfy( long theId )
121 if ( myMeshDS == 0 || myShape.IsNull() )
124 if( myType == SMDSAbs_Node )
126 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
128 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
129 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
130 switch( aTypeOfPosition )
132 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
133 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
134 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
135 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
141 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
143 if( myType == SMDSAbs_All )
145 return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
146 IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
147 IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
148 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
150 else if( myType == anElem->GetType() )
154 case SMDSAbs_Edge : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
155 case SMDSAbs_Face : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
156 case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
157 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
166 void Controls::BelongToGeom::SetType( SMDSAbs_ElementType theType )
171 SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
176 TopoDS_Shape Controls::BelongToGeom::GetShape()
182 Controls::BelongToGeom::
190 Description : Predicate for verifying whether entiy lying or partially lying on
191 specified geometrical support
194 Controls::LyingOnGeom::LyingOnGeom()
199 void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
201 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
204 void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
209 bool Controls::LyingOnGeom::IsSatisfy( long theId )
211 if ( myMeshDS == 0 || myShape.IsNull() )
214 if( myType == SMDSAbs_Node )
216 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
218 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
219 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
220 switch( aTypeOfPosition )
222 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
223 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
224 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
225 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
231 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
233 if( myType == SMDSAbs_All )
235 return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
236 Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
237 Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
238 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
240 else if( myType == anElem->GetType() )
244 case SMDSAbs_Edge : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
245 case SMDSAbs_Face : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
246 case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
247 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
256 void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
261 SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
266 TopoDS_Shape Controls::LyingOnGeom::GetShape()
272 Controls::LyingOnGeom::
278 bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh* theMeshDS,
279 const TopoDS_Shape& theShape,
280 const SMDS_MeshElement* theElem,
281 TopAbs_ShapeEnum theFindShapeEnum,
282 TopAbs_ShapeEnum theAvoidShapeEnum )
284 if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
287 TopTools_IndexedMapOfShape aSubShapes;
288 TopExp::MapShapes( theShape, aSubShapes );
290 for (int i = 1; i <= aSubShapes.Extent(); i++)
292 const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
294 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
295 if( aSubMesh->Contains( theElem ) )
298 SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
299 while ( aNodeIt->more() )
301 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
302 SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
303 while ( anElemIt->more() )
305 const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
306 if (anElement == theElem)
322 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
324 SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
325 return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
330 toArray( const TColStd_ListOfInteger& aList )
332 SMESH::long_array_var anArray = new SMESH::long_array;
333 anArray->length( aList.Extent() );
334 TColStd_ListIteratorOfListOfInteger anIter( aList );
336 for( ; anIter.More(); anIter.Next() )
337 anArray[ i++ ] = anIter.Value();
339 return anArray._retn();
344 toArray( const TColStd_ListOfReal& aList )
346 SMESH::double_array_var anArray = new SMESH::double_array;
347 anArray->length( aList.Extent() );
348 TColStd_ListIteratorOfListOfReal anIter( aList );
350 for( ; anIter.More(); anIter.Next() )
351 anArray[ i++ ] = anIter.Value();
353 return anArray._retn();
356 static SMESH::Filter::Criterion createCriterion()
358 SMESH::Filter::Criterion aCriterion;
360 aCriterion.Type = FT_Undefined;
361 aCriterion.Compare = FT_Undefined;
362 aCriterion.Threshold = 0;
363 aCriterion.UnaryOp = FT_Undefined;
364 aCriterion.BinaryOp = FT_Undefined;
365 aCriterion.ThresholdStr = "";
366 aCriterion.ThresholdID = "";
367 aCriterion.Tolerance = Precision::Confusion();
368 aCriterion.TypeOfElement = SMESH::ALL;
369 aCriterion.Precision = -1;
374 static TopoDS_Shape getShapeByName( const char* theName )
378 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
379 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
380 if (!CORBA::is_nil(aStudy))
382 SALOMEDS::Study::ListOfSObject_var aList =
383 aStudy->FindObjectByName( theName, "GEOM" );
384 if ( aList->length() > 0 )
386 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
387 if ( !aGeomObj->_is_nil() )
389 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
390 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
396 return TopoDS_Shape();
399 static TopoDS_Shape getShapeByID( const char* theID )
401 if ( theID != 0 && theID!="" )
403 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
404 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
407 CORBA::Object_var obj = aStudy->ConvertIORToObject(theID);
408 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( obj );
410 if ( !aGeomObj->_is_nil() )
412 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
413 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
418 return TopoDS_Shape();
421 static char* getShapeNameByID ( const char* theID )
425 if ( theID != 0 && theID!="" )
427 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
428 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
431 SALOMEDS::SObject_var aSObj = aStudy->FindObjectIOR( theID );
432 SALOMEDS::GenericAttribute_var anAttr;
433 if ( !aSObj->_is_nil() && aSObj->FindAttribute( anAttr, "AttributeName") )
435 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
436 aName = aNameAttr->Value();
450 Description : An abstact class for all functors
452 Functor_i::Functor_i():
453 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
455 // registration moved from constructor of abstract class
456 // to each ::Create* (creation of specific fucntor instance)
457 // to register fully declared this instance.
458 //PortableServer::ObjectId_var anObjectId =
459 // SMESH_Gen_i::GetPOA()->activate_object( this );
462 Functor_i::~Functor_i()
464 //TPythonDump()<<this<<".Destroy()";
467 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
469 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
470 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
473 ElementType Functor_i::GetElementType()
475 return ( ElementType )myFunctorPtr->GetType();
480 Class : NumericalFunctor_i
481 Description : Base class for numerical functors
483 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
485 return myNumericalFunctorPtr->GetValue( theId );
488 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
490 myNumericalFunctorPtr->SetPrecision( thePrecision );
491 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
494 CORBA::Long NumericalFunctor_i::GetPrecision()
496 return myNumericalFunctorPtr->GetPrecision();
499 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
501 return myNumericalFunctorPtr;
506 Class : SMESH_MinimumAngle
507 Description : Functor for calculation of minimum angle
509 MinimumAngle_i::MinimumAngle_i()
511 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
512 myFunctorPtr = myNumericalFunctorPtr;
515 FunctorType MinimumAngle_i::GetFunctorType()
517 return SMESH::FT_MinimumAngle;
523 Description : Functor for calculating aspect ratio
525 AspectRatio_i::AspectRatio_i()
527 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
528 myFunctorPtr = myNumericalFunctorPtr;
531 FunctorType AspectRatio_i::GetFunctorType()
533 return SMESH::FT_AspectRatio;
538 Class : AspectRatio3D
539 Description : Functor for calculating aspect ratio 3D
541 AspectRatio3D_i::AspectRatio3D_i()
543 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
544 myFunctorPtr = myNumericalFunctorPtr;
547 FunctorType AspectRatio3D_i::GetFunctorType()
549 return SMESH::FT_AspectRatio3D;
555 Description : Functor for calculating warping
557 Warping_i::Warping_i()
559 myNumericalFunctorPtr.reset( new Controls::Warping() );
560 myFunctorPtr = myNumericalFunctorPtr;
563 FunctorType Warping_i::GetFunctorType()
565 return SMESH::FT_Warping;
571 Description : Functor for calculating taper
575 myNumericalFunctorPtr.reset( new Controls::Taper() );
576 myFunctorPtr = myNumericalFunctorPtr;
579 FunctorType Taper_i::GetFunctorType()
581 return SMESH::FT_Taper;
587 Description : Functor for calculating skew in degrees
591 myNumericalFunctorPtr.reset( new Controls::Skew() );
592 myFunctorPtr = myNumericalFunctorPtr;
595 FunctorType Skew_i::GetFunctorType()
597 return SMESH::FT_Skew;
602 Description : Functor for calculating area
606 myNumericalFunctorPtr.reset( new Controls::Area() );
607 myFunctorPtr = myNumericalFunctorPtr;
610 FunctorType Area_i::GetFunctorType()
612 return SMESH::FT_Area;
617 Description : Functor for calculating volume of 3D element
619 Volume3D_i::Volume3D_i()
621 myNumericalFunctorPtr.reset( new Controls::Volume() );
622 myFunctorPtr = myNumericalFunctorPtr;
625 FunctorType Volume3D_i::GetFunctorType()
627 return SMESH::FT_Volume3D;
632 Description : Functor for calculating length off edge
636 myNumericalFunctorPtr.reset( new Controls::Length() );
637 myFunctorPtr = myNumericalFunctorPtr;
640 FunctorType Length_i::GetFunctorType()
642 return SMESH::FT_Length;
647 Description : Functor for calculating length of edge
649 Length2D_i::Length2D_i()
651 myNumericalFunctorPtr.reset( new Controls::Length2D() );
652 myFunctorPtr = myNumericalFunctorPtr;
655 FunctorType Length2D_i::GetFunctorType()
657 return SMESH::FT_Length2D;
660 SMESH::Length2D::Values* Length2D_i::GetValues()
662 INFOS("Length2D_i::GetValues");
663 SMESH::Controls::Length2D::TValues aValues;
664 myLength2DPtr->GetValues( aValues );
666 long i = 0, iEnd = aValues.size();
668 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
670 SMESH::Controls::Length2D::TValues::const_iterator anIter;
671 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
673 const SMESH::Controls::Length2D::Value& aVal = *anIter;
674 SMESH::Length2D::Value &aValue = aResult[ i ];
676 aValue.myLength = aVal.myLength;
677 aValue.myPnt1 = aVal.myPntId[ 0 ];
678 aValue.myPnt2 = aVal.myPntId[ 1 ];
681 INFOS("Length2D_i::GetValuess~");
682 return aResult._retn();
686 Class : MultiConnection_i
687 Description : Functor for calculating number of faces conneted to the edge
689 MultiConnection_i::MultiConnection_i()
691 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
692 myFunctorPtr = myNumericalFunctorPtr;
695 FunctorType MultiConnection_i::GetFunctorType()
697 return SMESH::FT_MultiConnection;
701 Class : MultiConnection2D_i
702 Description : Functor for calculating number of faces conneted to the edge
704 MultiConnection2D_i::MultiConnection2D_i()
706 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
707 myFunctorPtr = myNumericalFunctorPtr;
710 FunctorType MultiConnection2D_i::GetFunctorType()
712 return SMESH::FT_MultiConnection2D;
715 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
717 INFOS("MultiConnection2D_i::GetValues");
718 SMESH::Controls::MultiConnection2D::MValues aValues;
719 myMulticonnection2DPtr->GetValues( aValues );
721 long i = 0, iEnd = aValues.size();
723 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
725 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
726 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
728 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
729 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
731 aValue.myPnt1 = aVal.myPntId[ 0 ];
732 aValue.myPnt2 = aVal.myPntId[ 1 ];
733 aValue.myNbConnects = (*anIter).second;
736 INFOS("Multiconnection2D_i::GetValuess~");
737 return aResult._retn();
747 Description : Base class for all predicates
749 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
751 return myPredicatePtr->IsSatisfy( theId );
754 Controls::PredicatePtr Predicate_i::GetPredicate()
756 return myPredicatePtr;
760 Class : BadOrientedVolume_i
761 Description : Verify whether a mesh volume is incorrectly oriented from
762 the point of view of MED convention
764 BadOrientedVolume_i::BadOrientedVolume_i()
766 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
767 myFunctorPtr = myPredicatePtr = control;
770 FunctorType BadOrientedVolume_i::GetFunctorType()
772 return SMESH::FT_BadOrientedVolume;
776 Class : BelongToGeom_i
777 Description : Predicate for selection on geometrical support
779 BelongToGeom_i::BelongToGeom_i()
781 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
782 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
787 BelongToGeom_i::~BelongToGeom_i()
793 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
795 if ( theGeom->_is_nil() )
797 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
798 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
799 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
800 myBelongToGeomPtr->SetGeom( aLocShape );
801 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
804 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
806 myBelongToGeomPtr->SetGeom( theShape );
809 void BelongToGeom_i::SetElementType(ElementType theType){
810 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
811 TPythonDump()<<this<<".SetElementType("<<theType<<")";
814 FunctorType BelongToGeom_i::GetFunctorType()
816 return SMESH::FT_BelongToGeom;
819 void BelongToGeom_i::SetShapeName( const char* theName )
822 myShapeName = strdup( theName );
823 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
824 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
827 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
830 myShapeName = strdup( theName );
833 myShapeID = strdup( theID );
837 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
838 myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
840 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
843 char* BelongToGeom_i::GetShapeName()
845 return CORBA::string_dup( myShapeName );
848 char* BelongToGeom_i::GetShapeID()
850 return CORBA::string_dup( myShapeID );
854 Class : BelongToSurface_i
855 Description : Predicate for selection on geometrical support
857 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
859 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
860 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
863 mySurfaceType = theSurfaceType;
866 BelongToSurface_i::~BelongToSurface_i()
872 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
874 if ( theGeom->_is_nil() )
876 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
877 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
878 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
880 if ( aLocShape.ShapeType() == TopAbs_FACE )
882 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
883 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
885 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
890 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
891 TPythonDump()<<this<<".SetSurface("<<theGeom<<",'"<<theType<<"')";
894 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
897 myShapeName = strdup( theName );
898 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
899 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
902 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
905 myShapeName = strdup( theName );
908 myShapeID = strdup( theID );
912 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
913 myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
915 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
918 char* BelongToSurface_i::GetShapeName()
920 return CORBA::string_dup( myShapeName );
923 char* BelongToSurface_i::GetShapeID()
925 return CORBA::string_dup( myShapeID );
928 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
930 myElementsOnSurfacePtr->SetTolerance( theToler );
931 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
934 CORBA::Double BelongToSurface_i::GetTolerance()
936 return myElementsOnSurfacePtr->GetTolerance();
940 Class : BelongToPlane_i
941 Description : Verify whether mesh element lie in pointed Geom planar object
944 BelongToPlane_i::BelongToPlane_i()
945 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
949 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
951 BelongToSurface_i::SetSurface( theGeom, theType );
952 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
955 FunctorType BelongToPlane_i::GetFunctorType()
957 return FT_BelongToPlane;
961 Class : BelongToCylinder_i
962 Description : Verify whether mesh element lie in pointed Geom planar object
965 BelongToCylinder_i::BelongToCylinder_i()
966 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
970 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
972 BelongToSurface_i::SetSurface( theGeom, theType );
973 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
976 FunctorType BelongToCylinder_i::GetFunctorType()
978 return FT_BelongToCylinder;
982 Class : LyingOnGeom_i
983 Description : Predicate for selection on geometrical support
985 LyingOnGeom_i::LyingOnGeom_i()
987 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
988 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
993 LyingOnGeom_i::~LyingOnGeom_i()
999 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1001 if ( theGeom->_is_nil() )
1003 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1004 GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1005 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1006 myLyingOnGeomPtr->SetGeom( aLocShape );
1007 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1010 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1012 myLyingOnGeomPtr->SetGeom( theShape );
1015 void LyingOnGeom_i::SetElementType(ElementType theType){
1016 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1017 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1020 FunctorType LyingOnGeom_i::GetFunctorType()
1022 return SMESH::FT_LyingOnGeom;
1025 void LyingOnGeom_i::SetShapeName( const char* theName )
1028 myShapeName = strdup( theName );
1029 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1030 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1033 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1036 myShapeName = strdup( theName );
1039 myShapeID = strdup( theID );
1043 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1044 myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
1046 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1049 char* LyingOnGeom_i::GetShapeName()
1051 return CORBA::string_dup( myShapeName );
1054 char* LyingOnGeom_i::GetShapeID()
1056 return CORBA::string_dup( myShapeID );
1060 Class : FreeBorders_i
1061 Description : Predicate for free borders
1063 FreeBorders_i::FreeBorders_i()
1065 myPredicatePtr.reset(new Controls::FreeBorders());
1066 myFunctorPtr = myPredicatePtr;
1069 FunctorType FreeBorders_i::GetFunctorType()
1071 return SMESH::FT_FreeBorders;
1076 Description : Predicate for free borders
1078 FreeEdges_i::FreeEdges_i()
1079 : myFreeEdgesPtr( new Controls::FreeEdges() )
1081 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1084 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1086 INFOS("FreeEdges_i::GetBorders");
1087 SMESH::Controls::FreeEdges::TBorders aBorders;
1088 myFreeEdgesPtr->GetBoreders( aBorders );
1090 long i = 0, iEnd = aBorders.size();
1092 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1093 aResult->length(iEnd);
1095 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1096 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1098 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1099 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1101 aBorder.myElemId = aBord.myElemId;
1102 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1103 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1106 INFOS("FreeEdges_i::GetBorders~");
1107 return aResult._retn();
1110 FunctorType FreeEdges_i::GetFunctorType()
1112 return SMESH::FT_FreeEdges;
1116 Class : RangeOfIds_i
1117 Description : Predicate for Range of Ids.
1118 Range may be specified with two ways.
1119 1. Using AddToRange method
1120 2. With SetRangeStr method. Parameter of this method is a string
1121 like as "1,2,3,50-60,63,67,70-"
1124 RangeOfIds_i::RangeOfIds_i()
1126 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1127 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1130 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1132 CORBA::Long iEnd = theIds.length();
1133 for ( CORBA::Long i = 0; i < iEnd; i++ )
1134 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1135 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1138 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1140 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1141 return myRangeOfIdsPtr->SetRangeStr(
1142 TCollection_AsciiString( (Standard_CString)theRange ) );
1145 char* RangeOfIds_i::GetRangeStr()
1147 TCollection_AsciiString aStr;
1148 myRangeOfIdsPtr->GetRangeStr( aStr );
1149 return CORBA::string_dup( aStr.ToCString() );
1152 void RangeOfIds_i::SetElementType( ElementType theType )
1154 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1155 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1158 FunctorType RangeOfIds_i::GetFunctorType()
1160 return SMESH::FT_RangeOfIds;
1164 Class : Comparator_i
1165 Description : Base class for comparators
1167 Comparator_i::Comparator_i():
1168 myNumericalFunctor( NULL )
1171 Comparator_i::~Comparator_i()
1173 if ( myNumericalFunctor )
1174 myNumericalFunctor->Destroy();
1177 void Comparator_i::SetMargin( CORBA::Double theValue )
1179 myComparatorPtr->SetMargin( theValue );
1180 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1183 CORBA::Double Comparator_i::GetMargin()
1185 return myComparatorPtr->GetMargin();
1188 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1190 if ( myNumericalFunctor )
1191 myNumericalFunctor->Destroy();
1193 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1195 if ( myNumericalFunctor )
1197 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1198 myNumericalFunctor->Register();
1199 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1203 Controls::ComparatorPtr Comparator_i::GetComparator()
1205 return myComparatorPtr;
1208 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1210 return myNumericalFunctor;
1216 Description : Comparator "<"
1218 LessThan_i::LessThan_i()
1220 myComparatorPtr.reset( new Controls::LessThan() );
1221 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1224 FunctorType LessThan_i::GetFunctorType()
1226 return SMESH::FT_LessThan;
1232 Description : Comparator ">"
1234 MoreThan_i::MoreThan_i()
1236 myComparatorPtr.reset( new Controls::MoreThan() );
1237 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1240 FunctorType MoreThan_i::GetFunctorType()
1242 return SMESH::FT_MoreThan;
1248 Description : Comparator "="
1250 EqualTo_i::EqualTo_i()
1251 : myEqualToPtr( new Controls::EqualTo() )
1253 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1256 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1258 myEqualToPtr->SetTolerance( theToler );
1259 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1262 CORBA::Double EqualTo_i::GetTolerance()
1264 return myEqualToPtr->GetTolerance();
1267 FunctorType EqualTo_i::GetFunctorType()
1269 return SMESH::FT_EqualTo;
1273 Class : LogicalNOT_i
1274 Description : Logical NOT predicate
1276 LogicalNOT_i::LogicalNOT_i()
1277 : myPredicate( NULL ),
1278 myLogicalNOTPtr( new Controls::LogicalNOT() )
1280 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1283 LogicalNOT_i::~LogicalNOT_i()
1286 myPredicate->Destroy();
1289 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1292 myPredicate->Destroy();
1294 myPredicate = SMESH::GetPredicate(thePredicate);
1297 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1298 myPredicate->Register();
1299 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1303 FunctorType LogicalNOT_i::GetFunctorType()
1305 return SMESH::FT_LogicalNOT;
1308 Predicate_i* LogicalNOT_i::GetPredicate_i()
1315 Class : LogicalBinary_i
1316 Description : Base class for binary logical predicate
1318 LogicalBinary_i::LogicalBinary_i()
1319 : myPredicate1( NULL ),
1320 myPredicate2( NULL )
1323 LogicalBinary_i::~LogicalBinary_i()
1326 myPredicate1->Destroy();
1329 myPredicate2->Destroy();
1332 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1335 myPredicate1->SetMesh( theMesh );
1338 myPredicate2->SetMesh( theMesh );
1341 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1344 myPredicate1->Destroy();
1346 myPredicate1 = SMESH::GetPredicate(thePredicate);
1348 if ( myPredicate1 ){
1349 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1350 myPredicate1->Register();
1351 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1355 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1358 myPredicate2->Destroy();
1360 myPredicate2 = SMESH::GetPredicate(thePredicate);
1362 if ( myPredicate2 ){
1363 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1364 myPredicate2->Register();
1365 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1369 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1371 return myLogicalBinaryPtr;
1374 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1376 return myPredicate1;
1378 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1380 return myPredicate2;
1385 Class : LogicalAND_i
1386 Description : Logical AND
1388 LogicalAND_i::LogicalAND_i()
1390 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1391 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1394 FunctorType LogicalAND_i::GetFunctorType()
1396 return SMESH::FT_LogicalAND;
1402 Description : Logical OR
1404 LogicalOR_i::LogicalOR_i()
1406 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1407 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1410 FunctorType LogicalOR_i::GetFunctorType()
1412 return SMESH::FT_LogicalOR;
1420 FilterManager_i::FilterManager_i()
1421 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1423 // registration moved from constructor of abstract class
1424 // to each ::Create* (creation of specific fucntor instance)
1425 // to register fully declared this instance.
1426 //PortableServer::ObjectId_var anObjectId =
1427 // SMESH_Gen_i::GetPOA()->activate_object( this );
1431 FilterManager_i::~FilterManager_i()
1433 //TPythonDump()<<this<<".Destroy()";
1437 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1439 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1440 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1441 SMESH::MinimumAngle_var anObj = aServant->_this();
1442 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1443 return anObj._retn();
1447 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1449 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1450 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1451 SMESH::AspectRatio_var anObj = aServant->_this();
1452 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1453 return anObj._retn();
1457 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1459 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1460 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1461 SMESH::AspectRatio3D_var anObj = aServant->_this();
1462 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1463 return anObj._retn();
1467 Warping_ptr FilterManager_i::CreateWarping()
1469 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1470 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1471 SMESH::Warping_var anObj = aServant->_this();
1472 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1473 return anObj._retn();
1477 Taper_ptr FilterManager_i::CreateTaper()
1479 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1480 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1481 SMESH::Taper_var anObj = aServant->_this();
1482 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1483 return anObj._retn();
1487 Skew_ptr FilterManager_i::CreateSkew()
1489 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1490 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1491 SMESH::Skew_var anObj = aServant->_this();
1492 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1493 return anObj._retn();
1497 Area_ptr FilterManager_i::CreateArea()
1499 SMESH::Area_i* aServant = new SMESH::Area_i();
1500 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1501 SMESH::Area_var anObj = aServant->_this();
1502 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1503 return anObj._retn();
1507 Volume3D_ptr FilterManager_i::CreateVolume3D()
1509 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
1510 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1511 SMESH::Volume3D_var anObj = aServant->_this();
1512 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
1513 return anObj._retn();
1517 Length_ptr FilterManager_i::CreateLength()
1519 SMESH::Length_i* aServant = new SMESH::Length_i();
1520 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1521 SMESH::Length_var anObj = aServant->_this();
1522 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1523 return anObj._retn();
1526 Length2D_ptr FilterManager_i::CreateLength2D()
1528 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1529 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1530 SMESH::Length2D_var anObj = aServant->_this();
1531 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1532 return anObj._retn();
1535 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1537 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1538 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1539 SMESH::MultiConnection_var anObj = aServant->_this();
1540 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1541 return anObj._retn();
1544 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1546 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1547 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1548 SMESH::MultiConnection2D_var anObj = aServant->_this();
1549 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
1550 return anObj._retn();
1553 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1555 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1556 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1557 SMESH::BelongToGeom_var anObj = aServant->_this();
1558 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
1559 return anObj._retn();
1562 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1564 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1565 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1566 SMESH::BelongToPlane_var anObj = aServant->_this();
1567 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
1568 return anObj._retn();
1571 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1573 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1574 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1575 SMESH::BelongToCylinder_var anObj = aServant->_this();
1576 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
1577 return anObj._retn();
1580 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
1582 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
1583 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1584 SMESH::LyingOnGeom_var anObj = aServant->_this();
1585 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
1586 return anObj._retn();
1589 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1591 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1592 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1593 SMESH::FreeBorders_var anObj = aServant->_this();
1594 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
1595 return anObj._retn();
1598 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1600 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1601 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1602 SMESH::FreeEdges_var anObj = aServant->_this();
1603 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
1604 return anObj._retn();
1607 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1609 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1610 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1611 SMESH::RangeOfIds_var anObj = aServant->_this();
1612 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
1613 return anObj._retn();
1616 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
1618 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
1619 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1620 SMESH::BadOrientedVolume_var anObj = aServant->_this();
1621 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
1622 return anObj._retn();
1625 LessThan_ptr FilterManager_i::CreateLessThan()
1627 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1628 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1629 SMESH::LessThan_var anObj = aServant->_this();
1630 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
1631 return anObj._retn();
1635 MoreThan_ptr FilterManager_i::CreateMoreThan()
1637 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1638 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1639 SMESH::MoreThan_var anObj = aServant->_this();
1640 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
1641 return anObj._retn();
1644 EqualTo_ptr FilterManager_i::CreateEqualTo()
1646 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1647 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1648 SMESH::EqualTo_var anObj = aServant->_this();
1649 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
1650 return anObj._retn();
1654 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1656 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1657 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1658 SMESH::LogicalNOT_var anObj = aServant->_this();
1659 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
1660 return anObj._retn();
1664 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
1666 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
1667 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1668 SMESH::LogicalAND_var anObj = aServant->_this();
1669 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
1670 return anObj._retn();
1674 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
1676 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
1677 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1678 SMESH::LogicalOR_var anObj = aServant->_this();
1679 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
1680 return anObj._retn();
1683 Filter_ptr FilterManager_i::CreateFilter()
1685 SMESH::Filter_i* aServant = new SMESH::Filter_i();
1686 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1687 SMESH::Filter_var anObj = aServant->_this();
1688 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
1689 return anObj._retn();
1692 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
1694 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
1695 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1696 SMESH::FilterLibrary_var anObj = aServant->_this();
1697 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary("<<aFileName<<")";
1698 return anObj._retn();
1701 FilterLibrary_ptr FilterManager_i::CreateLibrary()
1703 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
1704 SMESH_Gen_i::GetPOA()->activate_object( aServant );
1705 SMESH::FilterLibrary_var anObj = aServant->_this();
1706 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
1707 return anObj._retn();
1710 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
1712 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
1713 return remove( aFileName ) ? false : true;
1716 //=============================================================================
1718 * SMESH_Gen_i::CreateFilterManager
1720 * Create filter manager
1722 //=============================================================================
1724 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
1726 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1727 SMESH_Gen_i::GetPOA()->activate_object( aFilter );
1728 SMESH::FilterManager_var anObj = aFilter->_this();
1729 return anObj._retn();
1737 //=======================================================================
1738 // name : Filter_i::Filter_i
1739 // Purpose : Constructor
1740 //=======================================================================
1741 Filter_i::Filter_i()
1742 : myPredicate( NULL )
1745 //=======================================================================
1746 // name : Filter_i::~Filter_i
1747 // Purpose : Destructor
1748 //=======================================================================
1749 Filter_i::~Filter_i()
1752 myPredicate->Destroy();
1754 if(!CORBA::is_nil(myMesh))
1757 //TPythonDump()<<this<<".Destroy()";
1760 //=======================================================================
1761 // name : Filter_i::SetPredicate
1762 // Purpose : Set predicate
1763 //=======================================================================
1764 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
1767 myPredicate->Destroy();
1769 myPredicate = SMESH::GetPredicate(thePredicate);
1773 myFilter.SetPredicate( myPredicate->GetPredicate() );
1774 myPredicate->Register();
1775 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1779 //=======================================================================
1780 // name : Filter_i::GetElementType
1781 // Purpose : Get entity type
1782 //=======================================================================
1783 SMESH::ElementType Filter_i::GetElementType()
1785 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
1788 //=======================================================================
1789 // name : Filter_i::SetMesh
1790 // Purpose : Set mesh
1791 //=======================================================================
1794 SetMesh( SMESH_Mesh_ptr theMesh )
1796 if(!CORBA::is_nil(theMesh))
1797 theMesh->Register();
1799 if(!CORBA::is_nil(myMesh))
1803 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
1810 return GetElementsId(myMesh);
1813 //=======================================================================
1814 // name : Filter_i::GetElementsId
1815 // Purpose : Get ids of entities
1816 //=======================================================================
1819 GetElementsId( Predicate_i* thePredicate,
1820 const SMDS_Mesh* theMesh,
1821 Controls::Filter::TIdSequence& theSequence )
1824 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
1829 GetElementsId( Predicate_i* thePredicate,
1830 SMESH_Mesh_ptr theMesh,
1831 Controls::Filter::TIdSequence& theSequence )
1834 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
1835 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
1840 GetElementsId( SMESH_Mesh_ptr theMesh )
1842 SMESH::long_array_var anArray = new SMESH::long_array;
1843 if(!CORBA::is_nil(theMesh) && myPredicate){
1844 Controls::Filter::TIdSequence aSequence;
1845 GetElementsId(myPredicate,theMesh,aSequence);
1846 long i = 0, iEnd = aSequence.size();
1847 anArray->length( iEnd );
1848 for ( ; i < iEnd; i++ )
1849 anArray[ i ] = aSequence[i];
1851 return anArray._retn();
1854 //=======================================================================
1855 // name : getCriteria
1856 // Purpose : Retrieve criterions from predicate
1857 //=======================================================================
1858 static inline bool getCriteria( Predicate_i* thePred,
1859 SMESH::Filter::Criteria_out theCriteria )
1861 int aFType = thePred->GetFunctorType();
1865 case FT_FreeBorders:
1868 CORBA::ULong i = theCriteria->length();
1869 theCriteria->length( i + 1 );
1871 theCriteria[ i ] = createCriterion();
1873 theCriteria[ i ].Type = aFType;
1874 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
1877 case FT_BelongToGeom:
1879 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
1881 CORBA::ULong i = theCriteria->length();
1882 theCriteria->length( i + 1 );
1884 theCriteria[ i ] = createCriterion();
1886 theCriteria[ i ].Type = FT_BelongToGeom;
1887 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1888 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1889 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1893 case FT_BelongToPlane:
1894 case FT_BelongToCylinder:
1896 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
1898 CORBA::ULong i = theCriteria->length();
1899 theCriteria->length( i + 1 );
1901 theCriteria[ i ] = createCriterion();
1903 theCriteria[ i ].Type = aFType;
1904 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1905 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1906 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1907 theCriteria[ i ].Tolerance = aPred->GetTolerance();
1911 case FT_LyingOnGeom:
1913 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
1915 CORBA::ULong i = theCriteria->length();
1916 theCriteria->length( i + 1 );
1918 theCriteria[ i ] = createCriterion();
1920 theCriteria[ i ].Type = FT_LyingOnGeom;
1921 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1922 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1923 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1929 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
1931 CORBA::ULong i = theCriteria->length();
1932 theCriteria->length( i + 1 );
1934 theCriteria[ i ] = createCriterion();
1936 theCriteria[ i ].Type = FT_RangeOfIds;
1937 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
1938 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1942 case FT_BadOrientedVolume:
1944 BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
1946 CORBA::ULong i = theCriteria->length();
1947 theCriteria->length( i + 1 );
1949 theCriteria[ i ] = createCriterion();
1951 theCriteria[ i ].Type = FT_BadOrientedVolume;
1952 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1960 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
1962 CORBA::ULong i = theCriteria->length();
1963 theCriteria->length( i + 1 );
1965 theCriteria[ i ] = createCriterion();
1967 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
1968 theCriteria[ i ].Compare = aFType;
1969 theCriteria[ i ].Threshold = aCompar->GetMargin();
1970 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
1972 if ( aFType == FT_EqualTo )
1974 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
1975 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
1982 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
1983 getCriteria( aPred, theCriteria );
1984 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
1991 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
1992 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
1993 if ( !getCriteria( aPred1, theCriteria ) )
1995 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
1996 return getCriteria( aPred2, theCriteria );
2006 //=======================================================================
2007 // name : Filter_i::GetCriteria
2008 // Purpose : Retrieve criterions from predicate
2009 //=======================================================================
2010 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2012 theCriteria = new SMESH::Filter::Criteria;
2013 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2016 //=======================================================================
2017 // name : Filter_i::SetCriteria
2018 // Purpose : Create new predicate and set criterions in it
2019 //=======================================================================
2020 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2022 if ( myPredicate != 0 )
2023 myPredicate->Destroy();
2025 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2026 SMESH_Gen_i::GetPOA()->activate_object( aFilter );
2027 FilterManager_ptr aFilterMgr = aFilter->_this();
2029 // CREATE two lists ( PREDICATES and LOG OP )
2032 TPythonDump()<<"aCriteria = []";
2033 std::list<SMESH::Predicate_ptr> aPredicates;
2034 std::list<int> aBinaries;
2035 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2037 int aCriterion = theCriteria[ i ].Type;
2038 int aCompare = theCriteria[ i ].Compare;
2039 double aThreshold = theCriteria[ i ].Threshold;
2040 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2041 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2042 int aUnary = theCriteria[ i ].UnaryOp;
2043 int aBinary = theCriteria[ i ].BinaryOp;
2044 double aTolerance = theCriteria[ i ].Tolerance;
2045 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
2046 long aPrecision = theCriteria[ i ].Precision;
2048 TPythonDump()<<"aCriteria.append(SMESH.Filter.Criterion("<<
2049 aCriterion<<","<<aCompare<<","<<aThreshold<<",'"<<aThresholdStr<<"','"<<aThresholdID<<"',"<<
2050 aUnary<<","<<aBinary<<","<<aTolerance<<","<<aTypeOfElem<<","<<aPrecision<<"))";
2052 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2053 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2055 switch ( aCriterion )
2059 case SMESH::FT_MultiConnection:
2060 aFunctor = aFilterMgr->CreateMultiConnection();
2062 case SMESH::FT_MultiConnection2D:
2063 aFunctor = aFilterMgr->CreateMultiConnection2D();
2065 case SMESH::FT_Length:
2066 aFunctor = aFilterMgr->CreateLength();
2068 case SMESH::FT_Length2D:
2069 aFunctor = aFilterMgr->CreateLength2D();
2071 case SMESH::FT_AspectRatio:
2072 aFunctor = aFilterMgr->CreateAspectRatio();
2074 case SMESH::FT_AspectRatio3D:
2075 aFunctor = aFilterMgr->CreateAspectRatio3D();
2077 case SMESH::FT_Warping:
2078 aFunctor = aFilterMgr->CreateWarping();
2080 case SMESH::FT_MinimumAngle:
2081 aFunctor = aFilterMgr->CreateMinimumAngle();
2083 case SMESH::FT_Taper:
2084 aFunctor = aFilterMgr->CreateTaper();
2086 case SMESH::FT_Skew:
2087 aFunctor = aFilterMgr->CreateSkew();
2089 case SMESH::FT_Area:
2090 aFunctor = aFilterMgr->CreateArea();
2092 case SMESH::FT_Volume3D:
2093 aFunctor = aFilterMgr->CreateVolume3D();
2098 case SMESH::FT_FreeBorders:
2099 aPredicate = aFilterMgr->CreateFreeBorders();
2101 case SMESH::FT_FreeEdges:
2102 aPredicate = aFilterMgr->CreateFreeEdges();
2104 case SMESH::FT_BelongToGeom:
2106 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2107 tmpPred->SetElementType( aTypeOfElem );
2108 tmpPred->SetShape( aThresholdID, aThresholdStr );
2109 aPredicate = tmpPred;
2112 case SMESH::FT_BelongToPlane:
2113 case SMESH::FT_BelongToCylinder:
2115 SMESH::BelongToSurface_ptr tmpPred;
2116 if ( aCriterion == SMESH::FT_BelongToPlane )
2117 tmpPred = aFilterMgr->CreateBelongToPlane();
2119 tmpPred = aFilterMgr->CreateBelongToCylinder();
2120 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2121 tmpPred->SetTolerance( aTolerance );
2122 aPredicate = tmpPred;
2125 case SMESH::FT_LyingOnGeom:
2127 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2128 tmpPred->SetElementType( aTypeOfElem );
2129 tmpPred->SetShape( aThresholdID, aThresholdStr );
2130 aPredicate = tmpPred;
2133 case SMESH::FT_RangeOfIds:
2135 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2136 tmpPred->SetRangeStr( aThresholdStr );
2137 tmpPred->SetElementType( aTypeOfElem );
2138 aPredicate = tmpPred;
2141 case SMESH::FT_BadOrientedVolume:
2143 aPredicate = aFilterMgr->CreateBadOrientedVolume();
2152 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
2154 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
2156 if ( aCompare == SMESH::FT_LessThan )
2157 aComparator = aFilterMgr->CreateLessThan();
2158 else if ( aCompare == SMESH::FT_MoreThan )
2159 aComparator = aFilterMgr->CreateMoreThan();
2160 else if ( aCompare == SMESH::FT_EqualTo )
2161 aComparator = aFilterMgr->CreateEqualTo();
2165 aComparator->SetNumFunctor( aFunctor );
2166 aComparator->SetMargin( aThreshold );
2168 if ( aCompare == FT_EqualTo )
2170 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
2171 anEqualTo->SetTolerance( aTolerance );
2174 aPredicate = aComparator;
2176 aFunctor->SetPrecision( aPrecision );
2180 if ( aUnary == FT_LogicalNOT )
2182 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
2183 aNotPred->SetPredicate( aPredicate );
2184 aPredicate = aNotPred;
2188 aPredicates.push_back( aPredicate );
2189 aBinaries.push_back( aBinary );
2192 TPythonDump()<<this<<".SetCriteria(aCriteria)";
2194 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
2196 // combine all "AND" operations
2198 std::list<SMESH::Predicate_ptr> aResList;
2200 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
2201 std::list<int>::iterator aBinaryIter;
2203 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
2204 int aPrevBinary = SMESH::FT_Undefined;
2206 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
2207 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
2208 ++aPredIter, ++aBinaryIter )
2210 int aCurrBinary = *aBinaryIter;
2212 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
2214 if ( aPrevBinary == SMESH::FT_LogicalAND )
2217 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2218 aBinaryPred->SetPredicate1( aPrevPredicate );
2219 aBinaryPred->SetPredicate2( *aPredIter );
2220 aCurrPred = aBinaryPred;
2223 aCurrPred = *aPredIter;
2225 if ( aCurrBinary != SMESH::FT_LogicalAND )
2226 aResList.push_back( aCurrPred );
2228 aPrevPredicate = aCurrPred;
2229 aPrevBinary = aCurrBinary;
2232 // combine all "OR" operations
2234 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2236 if ( aResList.size() == 1 )
2237 aResPredicate = *aResList.begin();
2238 else if ( aResList.size() > 1 )
2240 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2241 aResPredicate = *anIter;
2243 for ( ; anIter != aResList.end(); ++anIter )
2245 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2246 aBinaryPred->SetPredicate1( aResPredicate );
2247 aBinaryPred->SetPredicate2( *anIter );
2248 aResPredicate = aBinaryPred;
2252 SetPredicate( aResPredicate );
2254 return !aResPredicate->_is_nil();
2257 //=======================================================================
2258 // name : Filter_i::GetPredicate_i
2259 // Purpose : Get implementation of predicate
2260 //=======================================================================
2261 Predicate_i* Filter_i::GetPredicate_i()
2266 //=======================================================================
2267 // name : Filter_i::GetPredicate
2268 // Purpose : Get predicate
2269 //=======================================================================
2270 Predicate_ptr Filter_i::GetPredicate()
2272 if ( myPredicate == 0 )
2273 return SMESH::Predicate::_nil();
2276 SMESH::Predicate_var anObj = myPredicate->_this();
2277 return anObj._retn();
2285 #define ATTR_TYPE "type"
2286 #define ATTR_COMPARE "compare"
2287 #define ATTR_THRESHOLD "threshold"
2288 #define ATTR_UNARY "unary"
2289 #define ATTR_BINARY "binary"
2290 #define ATTR_THRESHOLD_STR "threshold_str"
2291 #define ATTR_TOLERANCE "tolerance"
2292 #define ATTR_ELEMENT_TYPE "ElementType"
2294 //=======================================================================
2296 // Purpose : Convert bool to LDOMString
2297 //=======================================================================
2298 static inline LDOMString toString( CORBA::Boolean val )
2300 return val ? "logical not" : "";
2303 //=======================================================================
2305 // Purpose : Convert LDOMString to bool
2306 //=======================================================================
2307 static inline bool toBool( const LDOMString& theStr )
2309 return theStr.equals( "logical not" );
2312 //=======================================================================
2314 // Purpose : Convert double to LDOMString
2315 //=======================================================================
2316 static inline LDOMString toString( CORBA::Double val )
2319 sprintf( a, "%e", val );
2320 return LDOMString( a );
2323 //=======================================================================
2325 // Purpose : Convert LDOMString to double
2326 //=======================================================================
2327 static inline double toDouble( const LDOMString& theStr )
2329 return atof( theStr.GetString() );
2332 //=======================================================================
2334 // Purpose : Convert functor type to LDOMString
2335 //=======================================================================
2336 static inline LDOMString toString( CORBA::Long theType )
2340 case FT_AspectRatio : return "Aspect ratio";
2341 case FT_Warping : return "Warping";
2342 case FT_MinimumAngle : return "Minimum angle";
2343 case FT_Taper : return "Taper";
2344 case FT_Skew : return "Skew";
2345 case FT_Area : return "Area";
2346 case FT_Volume3D : return "Volume3D";
2347 case FT_BelongToGeom : return "Belong to Geom";
2348 case FT_BelongToPlane : return "Belong to Plane";
2349 case FT_BelongToCylinder: return "Belong to Cylinder";
2350 case FT_LyingOnGeom : return "Lying on Geom";
2351 case FT_BadOrientedVolume: return "Bad Oriented Volume";
2352 case FT_RangeOfIds : return "Range of IDs";
2353 case FT_FreeBorders : return "Free borders";
2354 case FT_FreeEdges : return "Free edges";
2355 case FT_MultiConnection : return "Borders at multi-connections";
2356 case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2357 case FT_Length : return "Length";
2358 case FT_Length2D : return "Length2D";
2359 case FT_LessThan : return "Less than";
2360 case FT_MoreThan : return "More than";
2361 case FT_EqualTo : return "Equal to";
2362 case FT_LogicalNOT : return "Not";
2363 case FT_LogicalAND : return "And";
2364 case FT_LogicalOR : return "Or";
2365 case FT_Undefined : return "";
2366 default : return "";
2370 //=======================================================================
2371 // name : toFunctorType
2372 // Purpose : Convert LDOMString to functor type
2373 //=======================================================================
2374 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
2376 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
2377 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
2378 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
2379 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
2380 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
2381 else if ( theStr.equals( "Area" ) ) return FT_Area;
2382 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
2383 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
2384 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
2385 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
2386 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
2387 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
2388 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
2389 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
2390 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
2391 else if ( theStr.equals( "Length" ) ) return FT_Length;
2392 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
2393 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
2394 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
2395 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
2396 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
2397 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
2398 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
2399 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
2400 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
2401 else if ( theStr.equals( "" ) ) return FT_Undefined;
2402 else return FT_Undefined;
2405 //=======================================================================
2406 // name : toFunctorType
2407 // Purpose : Convert LDOMString to value of ElementType enumeration
2408 //=======================================================================
2409 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
2411 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
2412 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
2413 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
2414 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
2415 else return SMESH::ALL;
2418 //=======================================================================
2420 // Purpose : Convert ElementType to string
2421 //=======================================================================
2422 static inline LDOMString toString( const SMESH::ElementType theType )
2426 case SMESH::NODE : return "NODE";
2427 case SMESH::EDGE : return "EDGE";
2428 case SMESH::FACE : return "FACE";
2429 case SMESH::VOLUME : return "VOLUME";
2430 case SMESH::ALL : return "ALL";
2431 default : return "";
2435 //=======================================================================
2436 // name : findFilter
2437 // Purpose : Find filter in document
2438 //=======================================================================
2439 static LDOM_Element findFilter( const char* theFilterName,
2440 const LDOM_Document& theDoc,
2441 LDOM_Node* theParent = 0 )
2443 LDOM_Element aRootElement = theDoc.getDocumentElement();
2444 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
2445 return LDOM_Element();
2447 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
2448 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
2450 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
2451 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2453 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
2454 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
2455 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
2457 if ( theParent != 0 )
2458 *theParent = aTypeNode;
2459 return (LDOM_Element&)aFilter;
2463 return LDOM_Element();
2466 //=======================================================================
2467 // name : getSectionName
2468 // Purpose : Get name of section of filters
2469 //=======================================================================
2470 static const char* getSectionName( const ElementType theType )
2474 case SMESH::NODE : return "Filters for nodes";
2475 case SMESH::EDGE : return "Filters for edges";
2476 case SMESH::FACE : return "Filters for faces";
2477 case SMESH::VOLUME : return "Filters for volumes";
2478 case SMESH::ALL : return "Filters for elements";
2479 default : return "";
2483 //=======================================================================
2484 // name : getSection
2485 // Purpose : Create section for filters corresponding to the entity type
2486 //=======================================================================
2487 static LDOM_Node getSection( const ElementType theType,
2488 LDOM_Document& theDoc,
2489 const bool toCreate = false )
2491 LDOM_Element aRootElement = theDoc.getDocumentElement();
2492 if ( aRootElement.isNull() )
2496 bool anExist = false;
2497 const char* aSectionName = getSectionName( theType );
2498 if ( strcmp( aSectionName, "" ) == 0 )
2501 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
2503 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
2505 aNode = aSections.item( i );
2506 LDOM_Element& anItem = ( LDOM_Element& )aNode;
2507 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
2514 // Create new section if necessary
2519 LDOM_Element aNewItem = theDoc.createElement( "section" );
2520 aNewItem.setAttribute( "name", aSectionName );
2521 aRootElement.appendChild( aNewItem );
2531 //=======================================================================
2532 // name : createFilterItem
2533 // Purpose : Create filter item or LDOM document
2534 //=======================================================================
2535 static LDOM_Element createFilterItem( const char* theName,
2536 SMESH::Filter_ptr theFilter,
2537 LDOM_Document& theDoc )
2539 // create new filter in document
2540 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
2541 aFilterItem.setAttribute( "name", theName );
2543 // save filter criterions
2544 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2546 if ( !theFilter->GetCriteria( aCriteria ) )
2547 return LDOM_Element();
2549 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
2551 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
2553 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
2554 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
2555 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
2556 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
2557 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
2559 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
2560 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
2561 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
2562 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
2564 aFilterItem.appendChild( aCriterionItem );
2570 //=======================================================================
2571 // name : FilterLibrary_i::FilterLibrary_i
2572 // Purpose : Constructor
2573 //=======================================================================
2574 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
2576 myFileName = strdup( theFileName );
2577 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
2578 SMESH_Gen_i::GetPOA()->activate_object( aFilterMgr );
2579 myFilterMgr = aFilterMgr->_this();
2583 // Try to use existing library file
2584 bool anExists = false;
2585 if ( !aParser.parse( myFileName ) )
2587 myDoc = aParser.getDocument();
2590 // Create a new XML document if it doesn't exist
2592 myDoc = LDOM_Document::createDocument( LDOMString() );
2594 LDOM_Element aRootElement = myDoc.getDocumentElement();
2595 if ( aRootElement.isNull() )
2597 // If the existing document is empty --> try to create a new one
2599 myDoc = LDOM_Document::createDocument( LDOMString() );
2603 //=======================================================================
2604 // name : FilterLibrary_i::FilterLibrary_i
2605 // Purpose : Constructor
2606 //=======================================================================
2607 FilterLibrary_i::FilterLibrary_i()
2610 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2611 SMESH_Gen_i::GetPOA()->activate_object( aFilter );
2612 myFilterMgr = aFilter->_this();
2614 myDoc = LDOM_Document::createDocument( LDOMString() );
2617 FilterLibrary_i::~FilterLibrary_i()
2620 //TPythonDump()<<this<<".Destroy()";
2623 //=======================================================================
2624 // name : FilterLibrary_i::Copy
2625 // Purpose : Create filter and initialize it with values from library
2626 //=======================================================================
2627 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
2629 Filter_ptr aRes = Filter::_nil();
2630 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
2632 if ( aFilter.isNull() )
2635 std::list<SMESH::Filter::Criterion> aCriteria;
2637 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
2638 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
2640 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
2642 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
2643 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
2644 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
2645 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
2646 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
2648 SMESH::Filter::Criterion aCriterion = createCriterion();
2650 aCriterion.Type = toFunctorType( aTypeStr );
2651 aCriterion.Compare = toFunctorType( aCompareStr );
2652 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
2653 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
2655 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
2657 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
2659 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2660 ? val : atof( str.GetString() );
2662 str = aCrit->getAttribute( ATTR_TOLERANCE );
2663 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2664 ? val : atof( str.GetString() );
2666 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
2667 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
2670 sprintf( a, "%d", val );
2671 aCriterion.ThresholdStr = strdup( a );
2674 aCriterion.ThresholdStr = str.GetString();
2676 aCriteria.push_back( aCriterion );
2679 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
2680 aCriteriaVar->length( aCriteria.size() );
2683 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
2685 for( ; anIter != aCriteria.end(); ++anIter )
2686 aCriteriaVar[ i++ ] = *anIter;
2688 aRes = myFilterMgr->CreateFilter();
2689 aRes->SetCriteria( aCriteriaVar.inout() );
2691 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
2696 //=======================================================================
2697 // name : FilterLibrary_i::SetFileName
2698 // Purpose : Set file name for library
2699 //=======================================================================
2700 void FilterLibrary_i::SetFileName( const char* theFileName )
2703 myFileName = strdup( theFileName );
2704 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
2707 //=======================================================================
2708 // name : FilterLibrary_i::GetFileName
2709 // Purpose : Get file name of library
2710 //=======================================================================
2711 char* FilterLibrary_i::GetFileName()
2713 return CORBA::string_dup( myFileName );
2716 //=======================================================================
2717 // name : FilterLibrary_i::Add
2718 // Purpose : Add new filter to library
2719 //=======================================================================
2720 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
2722 // if filter already in library or entry filter is null do nothing
2723 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2724 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
2727 // get section corresponding to the filter type
2728 ElementType anEntType = theFilter->GetElementType();
2730 LDOM_Node aSection = getSection( anEntType, myDoc, true );
2731 if ( aSection.isNull() )
2734 // create filter item
2735 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
2736 if ( aFilterItem.isNull() )
2740 aSection.appendChild( aFilterItem );
2741 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2742 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
2747 //=======================================================================
2748 // name : FilterLibrary_i::Add
2749 // Purpose : Add new filter to library
2750 //=======================================================================
2751 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
2753 // if filter already in library or entry filter is null do nothing
2754 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2755 if ( !aFilterNode.isNull() )
2758 LDOM_Node aSection = getSection( theType, myDoc, true );
2759 if ( aSection.isNull() )
2762 // create filter item
2763 Filter_var aFilter = myFilterMgr->CreateFilter();
2765 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
2766 if ( aFilterItem.isNull() )
2770 aSection.appendChild( aFilterItem );
2771 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
2776 //=======================================================================
2777 // name : FilterLibrary_i::Delete
2778 // Purpose : Delete filter from library
2779 //=======================================================================
2780 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
2782 LDOM_Node aParentNode;
2783 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
2784 if ( aFilterNode.isNull() || aParentNode.isNull() )
2787 aParentNode.removeChild( aFilterNode );
2788 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
2792 //=======================================================================
2793 // name : FilterLibrary_i::Replace
2794 // Purpose : Replace existing filter with entry filter.
2795 // IMPORTANT : If filter does not exist it is not created
2796 //=======================================================================
2797 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
2798 const char* theNewName,
2799 Filter_ptr theFilter )
2801 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
2802 if ( aFilterItem.isNull() || theFilter->_is_nil() )
2805 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
2806 if ( aNewItem.isNull() )
2810 aFilterItem.ReplaceElement( aNewItem );
2811 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2812 TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
2817 //=======================================================================
2818 // name : FilterLibrary_i::Save
2819 // Purpose : Save library on disk
2820 //=======================================================================
2821 CORBA::Boolean FilterLibrary_i::Save()
2823 if ( myFileName == 0 || strlen( myFileName ) == 0 )
2826 FILE* aOutFile = fopen( myFileName, "wt" );
2830 LDOM_XmlWriter aWriter( aOutFile );
2831 aWriter.SetIndentation( 2 );
2835 TPythonDump()<<this<<".Save()";
2839 //=======================================================================
2840 // name : FilterLibrary_i::SaveAs
2841 // Purpose : Save library on disk
2842 //=======================================================================
2843 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
2845 myFileName = strdup ( aFileName );
2846 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
2850 //=======================================================================
2851 // name : FilterLibrary_i::IsPresent
2852 // Purpose : Verify whether filter is in library
2853 //=======================================================================
2854 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
2856 return !findFilter( theFilterName, myDoc ).isNull();
2859 //=======================================================================
2860 // name : FilterLibrary_i::NbFilters
2861 // Purpose : Return amount of filters in library
2862 //=======================================================================
2863 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
2865 string_array_var aNames = GetNames( theType );
2866 return aNames->length();
2869 //=======================================================================
2870 // name : FilterLibrary_i::GetNames
2871 // Purpose : Get names of filters from library
2872 //=======================================================================
2873 string_array* FilterLibrary_i::GetNames( ElementType theType )
2875 string_array_var anArray = new string_array;
2876 TColStd_SequenceOfHAsciiString aSeq;
2878 LDOM_Node aSection = getSection( theType, myDoc, false );
2880 if ( !aSection.isNull() )
2882 for ( LDOM_Node aFilter = aSection.getFirstChild();
2883 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2885 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
2886 aSeq.Append( new TCollection_HAsciiString(
2887 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
2891 anArray->length( aSeq.Length() );
2892 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
2893 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
2895 return anArray._retn();
2898 //=======================================================================
2899 // name : FilterLibrary_i::GetAllNames
2900 // Purpose : Get names of filters from library
2901 //=======================================================================
2902 string_array* FilterLibrary_i::GetAllNames()
2904 string_array_var aResArray = new string_array;
2905 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
2907 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
2909 int aPrevLength = aResArray->length();
2910 aResArray->length( aPrevLength + aNames->length() );
2911 for ( int i = 0, n = aNames->length(); i < n; i++ )
2912 aResArray[ aPrevLength + i ] = aNames[ i ];
2915 return aResArray._retn();