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 <BRep_Tool.hxx>
41 #include <Geom_CylindricalSurface.hxx>
42 #include <Geom_Plane.hxx>
43 #include <LDOMParser.hxx>
44 #include <LDOMString.hxx>
45 #include <LDOM_Document.hxx>
46 #include <LDOM_Element.hxx>
47 #include <LDOM_Node.hxx>
48 #include <LDOM_XmlWriter.hxx>
49 #include <Precision.hxx>
50 #include <TColStd_ListIteratorOfListOfInteger.hxx>
51 #include <TColStd_ListIteratorOfListOfReal.hxx>
52 #include <TColStd_ListOfInteger.hxx>
53 #include <TColStd_ListOfReal.hxx>
54 #include <TColStd_SequenceOfHAsciiString.hxx>
55 #include <TCollection_HAsciiString.hxx>
57 #include <TopExp_Explorer.hxx>
59 #include <TopoDS_Face.hxx>
60 #include <TopoDS_Shape.hxx>
62 using namespace SMESH;
63 using namespace SMESH::Controls;
69 GetPredicate( Predicate_ptr thePredicate )
71 return DownCast<Predicate_i*>(thePredicate);
78 Description : Predicate for verifying whether entiy belong to
79 specified geometrical support
82 Controls::BelongToGeom::BelongToGeom()
87 void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
89 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
92 void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
97 static bool IsContains( const SMESHDS_Mesh* theMeshDS,
98 const TopoDS_Shape& theShape,
99 const SMDS_MeshElement* theElem,
100 TopAbs_ShapeEnum theFindShapeEnum,
101 TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE )
103 TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
105 while( anExp.More() )
107 const TopoDS_Shape& aShape = anExp.Current();
108 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
109 if( aSubMesh->Contains( theElem ) )
117 bool Controls::BelongToGeom::IsSatisfy( long theId )
119 if ( myMeshDS == 0 || myShape.IsNull() )
122 if( myType == SMDSAbs_Node )
124 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
126 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
127 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
128 switch( aTypeOfPosition )
130 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
131 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
132 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
133 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
139 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
141 if( myType == SMDSAbs_All )
143 return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
144 IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
145 IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
146 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
148 else if( myType == anElem->GetType() )
152 case SMDSAbs_Edge : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
153 case SMDSAbs_Face : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
154 case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
155 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
164 void Controls::BelongToGeom::SetType( SMDSAbs_ElementType theType )
169 SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
174 TopoDS_Shape Controls::BelongToGeom::GetShape()
180 Controls::BelongToGeom::
188 Description : Predicate for verifying whether entiy lying or partially lying on
189 specified geometrical support
192 Controls::LyingOnGeom::LyingOnGeom()
197 void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
199 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
202 void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
207 bool Controls::LyingOnGeom::IsSatisfy( long theId )
209 if ( myMeshDS == 0 || myShape.IsNull() )
212 if( myType == SMDSAbs_Node )
214 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
216 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
217 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
218 switch( aTypeOfPosition )
220 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
221 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
222 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
223 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
229 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
231 if( myType == SMDSAbs_All )
233 return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
234 Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
235 Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
236 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
238 else if( myType == anElem->GetType() )
242 case SMDSAbs_Edge : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
243 case SMDSAbs_Face : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
244 case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
245 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
254 void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
259 SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
264 TopoDS_Shape Controls::LyingOnGeom::GetShape()
270 Controls::LyingOnGeom::
276 bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh* theMeshDS,
277 const TopoDS_Shape& theShape,
278 const SMDS_MeshElement* theElem,
279 TopAbs_ShapeEnum theFindShapeEnum,
280 TopAbs_ShapeEnum theAvoidShapeEnum )
282 if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
285 TopTools_IndexedMapOfShape aSubShapes;
286 TopExp::MapShapes( theShape, aSubShapes );
288 for (int i = 1; i <= aSubShapes.Extent(); i++)
290 const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
292 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
293 if( aSubMesh->Contains( theElem ) )
296 SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
297 while ( aNodeIt->more() )
299 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
300 SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
301 while ( anElemIt->more() )
303 const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
304 if (anElement == theElem)
320 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
322 SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
323 return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
328 toArray( const TColStd_ListOfInteger& aList )
330 SMESH::long_array_var anArray = new SMESH::long_array;
331 anArray->length( aList.Extent() );
332 TColStd_ListIteratorOfListOfInteger anIter( aList );
334 for( ; anIter.More(); anIter.Next() )
335 anArray[ i++ ] = anIter.Value();
337 return anArray._retn();
342 toArray( const TColStd_ListOfReal& aList )
344 SMESH::double_array_var anArray = new SMESH::double_array;
345 anArray->length( aList.Extent() );
346 TColStd_ListIteratorOfListOfReal anIter( aList );
348 for( ; anIter.More(); anIter.Next() )
349 anArray[ i++ ] = anIter.Value();
351 return anArray._retn();
354 static SMESH::Filter::Criterion createCriterion()
356 SMESH::Filter::Criterion aCriterion;
358 aCriterion.Type = FT_Undefined;
359 aCriterion.Compare = FT_Undefined;
360 aCriterion.Threshold = 0;
361 aCriterion.UnaryOp = FT_Undefined;
362 aCriterion.BinaryOp = FT_Undefined;
363 aCriterion.ThresholdStr = "";
364 aCriterion.ThresholdID = "";
365 aCriterion.Tolerance = Precision::Confusion();
366 aCriterion.TypeOfElement = SMESH::ALL;
367 aCriterion.Precision = -1;
372 static TopoDS_Shape getShapeByName( const char* theName )
376 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
377 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
378 if (!CORBA::is_nil(aStudy))
380 SALOMEDS::Study::ListOfSObject_var aList =
381 aStudy->FindObjectByName( theName, "GEOM" );
382 if ( aList->length() > 0 )
384 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
385 if ( !aGeomObj->_is_nil() )
387 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
388 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
394 return TopoDS_Shape();
397 static TopoDS_Shape getShapeByID (const char* theID)
399 if (theID != 0 && theID != "") {
400 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
401 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
403 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
404 SALOMEDS::GenericAttribute_var anAttr;
405 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
406 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
407 CORBA::String_var aVal = anIOR->Value();
408 CORBA::Object_var obj = aStudy->ConvertIORToObject(aVal);
409 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
411 if (!aGeomObj->_is_nil()) {
412 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
413 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
419 return TopoDS_Shape();
422 static char* getShapeNameByID (const char* theID)
426 if (theID != 0 && theID != "") {
427 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
428 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
430 //SALOMEDS::SObject_var aSObj = aStudy->FindObjectIOR( theID );
431 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
432 SALOMEDS::GenericAttribute_var anAttr;
433 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeName")) {
434 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
435 aName = aNameAttr->Value();
449 Description : An abstact class for all functors
451 Functor_i::Functor_i():
452 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
454 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
455 //PortableServer::ObjectId_var anObjectId =
456 // SMESH_Gen_i::GetPOA()->activate_object( this );
459 Functor_i::~Functor_i()
461 //TPythonDump()<<this<<".Destroy()";
464 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
466 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
467 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
470 ElementType Functor_i::GetElementType()
472 return ( ElementType )myFunctorPtr->GetType();
477 Class : NumericalFunctor_i
478 Description : Base class for numerical functors
480 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
482 return myNumericalFunctorPtr->GetValue( theId );
485 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
487 myNumericalFunctorPtr->SetPrecision( thePrecision );
488 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
491 CORBA::Long NumericalFunctor_i::GetPrecision()
493 return myNumericalFunctorPtr->GetPrecision();
496 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
498 return myNumericalFunctorPtr;
503 Class : SMESH_MinimumAngle
504 Description : Functor for calculation of minimum angle
506 MinimumAngle_i::MinimumAngle_i()
508 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
509 myFunctorPtr = myNumericalFunctorPtr;
512 FunctorType MinimumAngle_i::GetFunctorType()
514 return SMESH::FT_MinimumAngle;
520 Description : Functor for calculating aspect ratio
522 AspectRatio_i::AspectRatio_i()
524 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
525 myFunctorPtr = myNumericalFunctorPtr;
528 FunctorType AspectRatio_i::GetFunctorType()
530 return SMESH::FT_AspectRatio;
535 Class : AspectRatio3D
536 Description : Functor for calculating aspect ratio 3D
538 AspectRatio3D_i::AspectRatio3D_i()
540 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
541 myFunctorPtr = myNumericalFunctorPtr;
544 FunctorType AspectRatio3D_i::GetFunctorType()
546 return SMESH::FT_AspectRatio3D;
552 Description : Functor for calculating warping
554 Warping_i::Warping_i()
556 myNumericalFunctorPtr.reset( new Controls::Warping() );
557 myFunctorPtr = myNumericalFunctorPtr;
560 FunctorType Warping_i::GetFunctorType()
562 return SMESH::FT_Warping;
568 Description : Functor for calculating taper
572 myNumericalFunctorPtr.reset( new Controls::Taper() );
573 myFunctorPtr = myNumericalFunctorPtr;
576 FunctorType Taper_i::GetFunctorType()
578 return SMESH::FT_Taper;
584 Description : Functor for calculating skew in degrees
588 myNumericalFunctorPtr.reset( new Controls::Skew() );
589 myFunctorPtr = myNumericalFunctorPtr;
592 FunctorType Skew_i::GetFunctorType()
594 return SMESH::FT_Skew;
599 Description : Functor for calculating area
603 myNumericalFunctorPtr.reset( new Controls::Area() );
604 myFunctorPtr = myNumericalFunctorPtr;
607 FunctorType Area_i::GetFunctorType()
609 return SMESH::FT_Area;
614 Description : Functor for calculating volume of 3D element
616 Volume3D_i::Volume3D_i()
618 myNumericalFunctorPtr.reset( new Controls::Volume() );
619 myFunctorPtr = myNumericalFunctorPtr;
622 FunctorType Volume3D_i::GetFunctorType()
624 return SMESH::FT_Volume3D;
629 Description : Functor for calculating length off edge
633 myNumericalFunctorPtr.reset( new Controls::Length() );
634 myFunctorPtr = myNumericalFunctorPtr;
637 FunctorType Length_i::GetFunctorType()
639 return SMESH::FT_Length;
644 Description : Functor for calculating length of edge
646 Length2D_i::Length2D_i()
648 myNumericalFunctorPtr.reset( new Controls::Length2D() );
649 myFunctorPtr = myNumericalFunctorPtr;
652 FunctorType Length2D_i::GetFunctorType()
654 return SMESH::FT_Length2D;
657 SMESH::Length2D::Values* Length2D_i::GetValues()
659 INFOS("Length2D_i::GetValues");
660 SMESH::Controls::Length2D::TValues aValues;
661 myLength2DPtr->GetValues( aValues );
663 long i = 0, iEnd = aValues.size();
665 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
667 SMESH::Controls::Length2D::TValues::const_iterator anIter;
668 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
670 const SMESH::Controls::Length2D::Value& aVal = *anIter;
671 SMESH::Length2D::Value &aValue = aResult[ i ];
673 aValue.myLength = aVal.myLength;
674 aValue.myPnt1 = aVal.myPntId[ 0 ];
675 aValue.myPnt2 = aVal.myPntId[ 1 ];
678 INFOS("Length2D_i::GetValuess~");
679 return aResult._retn();
683 Class : MultiConnection_i
684 Description : Functor for calculating number of faces conneted to the edge
686 MultiConnection_i::MultiConnection_i()
688 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
689 myFunctorPtr = myNumericalFunctorPtr;
692 FunctorType MultiConnection_i::GetFunctorType()
694 return SMESH::FT_MultiConnection;
698 Class : MultiConnection2D_i
699 Description : Functor for calculating number of faces conneted to the edge
701 MultiConnection2D_i::MultiConnection2D_i()
703 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
704 myFunctorPtr = myNumericalFunctorPtr;
707 FunctorType MultiConnection2D_i::GetFunctorType()
709 return SMESH::FT_MultiConnection2D;
712 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
714 INFOS("MultiConnection2D_i::GetValues");
715 SMESH::Controls::MultiConnection2D::MValues aValues;
716 myMulticonnection2DPtr->GetValues( aValues );
718 long i = 0, iEnd = aValues.size();
720 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
722 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
723 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
725 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
726 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
728 aValue.myPnt1 = aVal.myPntId[ 0 ];
729 aValue.myPnt2 = aVal.myPntId[ 1 ];
730 aValue.myNbConnects = (*anIter).second;
733 INFOS("Multiconnection2D_i::GetValuess~");
734 return aResult._retn();
744 Description : Base class for all predicates
746 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
748 return myPredicatePtr->IsSatisfy( theId );
751 Controls::PredicatePtr Predicate_i::GetPredicate()
753 return myPredicatePtr;
757 Class : BadOrientedVolume_i
758 Description : Verify whether a mesh volume is incorrectly oriented from
759 the point of view of MED convention
761 BadOrientedVolume_i::BadOrientedVolume_i()
763 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
764 myFunctorPtr = myPredicatePtr = control;
767 FunctorType BadOrientedVolume_i::GetFunctorType()
769 return SMESH::FT_BadOrientedVolume;
773 Class : BelongToGeom_i
774 Description : Predicate for selection on geometrical support
776 BelongToGeom_i::BelongToGeom_i()
778 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
779 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
784 BelongToGeom_i::~BelongToGeom_i()
790 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
792 if ( theGeom->_is_nil() )
794 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
795 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
796 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
797 myBelongToGeomPtr->SetGeom( aLocShape );
798 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
801 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
803 myBelongToGeomPtr->SetGeom( theShape );
806 void BelongToGeom_i::SetElementType(ElementType theType){
807 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
808 TPythonDump()<<this<<".SetElementType("<<theType<<")";
811 FunctorType BelongToGeom_i::GetFunctorType()
813 return SMESH::FT_BelongToGeom;
816 void BelongToGeom_i::SetShapeName( const char* theName )
819 myShapeName = strdup( theName );
820 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
821 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
824 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
827 myShapeName = strdup( theName );
830 myShapeID = strdup( theID );
834 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
835 myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
837 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
840 char* BelongToGeom_i::GetShapeName()
842 return CORBA::string_dup( myShapeName );
845 char* BelongToGeom_i::GetShapeID()
847 return CORBA::string_dup( myShapeID );
851 Class : BelongToSurface_i
852 Description : Predicate for selection on geometrical support
854 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
856 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
857 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
860 mySurfaceType = theSurfaceType;
863 BelongToSurface_i::~BelongToSurface_i()
869 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
871 if ( theGeom->_is_nil() )
873 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
874 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
875 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
877 if ( aLocShape.ShapeType() == TopAbs_FACE )
879 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
880 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
882 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
887 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
890 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
893 myShapeName = strdup( theName );
894 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
895 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
898 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
901 myShapeName = strdup( theName );
904 myShapeID = strdup( theID );
908 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
909 myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
911 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
914 char* BelongToSurface_i::GetShapeName()
916 return CORBA::string_dup( myShapeName );
919 char* BelongToSurface_i::GetShapeID()
921 return CORBA::string_dup( myShapeID );
924 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
926 myElementsOnSurfacePtr->SetTolerance( theToler );
927 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
930 CORBA::Double BelongToSurface_i::GetTolerance()
932 return myElementsOnSurfacePtr->GetTolerance();
935 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
937 myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
938 TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
941 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
943 return myElementsOnSurfacePtr->GetUseBoundaries();
948 Class : BelongToPlane_i
949 Description : Verify whether mesh element lie in pointed Geom planar object
952 BelongToPlane_i::BelongToPlane_i()
953 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
957 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
959 BelongToSurface_i::SetSurface( theGeom, theType );
960 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
963 FunctorType BelongToPlane_i::GetFunctorType()
965 return FT_BelongToPlane;
969 Class : BelongToCylinder_i
970 Description : Verify whether mesh element lie in pointed Geom planar object
973 BelongToCylinder_i::BelongToCylinder_i()
974 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
978 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
980 BelongToSurface_i::SetSurface( theGeom, theType );
981 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
984 FunctorType BelongToCylinder_i::GetFunctorType()
986 return FT_BelongToCylinder;
990 Class : BelongToGenSurface_i
991 Description : Verify whether mesh element lie in pointed Geom planar object
994 BelongToGenSurface_i::BelongToGenSurface_i()
995 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
999 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1001 if ( theGeom->_is_nil() )
1003 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1004 if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1005 aLocShape.Nullify();
1007 BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1008 TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1011 FunctorType BelongToGenSurface_i::GetFunctorType()
1013 return FT_BelongToGenSurface;
1017 Class : LyingOnGeom_i
1018 Description : Predicate for selection on geometrical support
1020 LyingOnGeom_i::LyingOnGeom_i()
1022 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1023 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1028 LyingOnGeom_i::~LyingOnGeom_i()
1034 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1036 if ( theGeom->_is_nil() )
1038 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1039 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1040 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1041 myLyingOnGeomPtr->SetGeom( aLocShape );
1042 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1045 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1047 myLyingOnGeomPtr->SetGeom( theShape );
1050 void LyingOnGeom_i::SetElementType(ElementType theType){
1051 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1052 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1055 FunctorType LyingOnGeom_i::GetFunctorType()
1057 return SMESH::FT_LyingOnGeom;
1060 void LyingOnGeom_i::SetShapeName( const char* theName )
1063 myShapeName = strdup( theName );
1064 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1065 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1068 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1071 myShapeName = strdup( theName );
1074 myShapeID = strdup( theID );
1078 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1079 myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
1081 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1084 char* LyingOnGeom_i::GetShapeName()
1086 return CORBA::string_dup( myShapeName );
1089 char* LyingOnGeom_i::GetShapeID()
1091 return CORBA::string_dup( myShapeID );
1095 Class : FreeBorders_i
1096 Description : Predicate for free borders
1098 FreeBorders_i::FreeBorders_i()
1100 myPredicatePtr.reset(new Controls::FreeBorders());
1101 myFunctorPtr = myPredicatePtr;
1104 FunctorType FreeBorders_i::GetFunctorType()
1106 return SMESH::FT_FreeBorders;
1111 Description : Predicate for free borders
1113 FreeEdges_i::FreeEdges_i()
1114 : myFreeEdgesPtr( new Controls::FreeEdges() )
1116 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1119 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1121 INFOS("FreeEdges_i::GetBorders");
1122 SMESH::Controls::FreeEdges::TBorders aBorders;
1123 myFreeEdgesPtr->GetBoreders( aBorders );
1125 long i = 0, iEnd = aBorders.size();
1127 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1128 aResult->length(iEnd);
1130 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1131 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1133 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1134 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1136 aBorder.myElemId = aBord.myElemId;
1137 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1138 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1141 INFOS("FreeEdges_i::GetBorders~");
1142 return aResult._retn();
1145 FunctorType FreeEdges_i::GetFunctorType()
1147 return SMESH::FT_FreeEdges;
1151 Class : RangeOfIds_i
1152 Description : Predicate for Range of Ids.
1153 Range may be specified with two ways.
1154 1. Using AddToRange method
1155 2. With SetRangeStr method. Parameter of this method is a string
1156 like as "1,2,3,50-60,63,67,70-"
1159 RangeOfIds_i::RangeOfIds_i()
1161 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1162 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1165 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1167 CORBA::Long iEnd = theIds.length();
1168 for ( CORBA::Long i = 0; i < iEnd; i++ )
1169 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1170 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1173 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1175 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1176 return myRangeOfIdsPtr->SetRangeStr(
1177 TCollection_AsciiString( (Standard_CString)theRange ) );
1180 char* RangeOfIds_i::GetRangeStr()
1182 TCollection_AsciiString aStr;
1183 myRangeOfIdsPtr->GetRangeStr( aStr );
1184 return CORBA::string_dup( aStr.ToCString() );
1187 void RangeOfIds_i::SetElementType( ElementType theType )
1189 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1190 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1193 FunctorType RangeOfIds_i::GetFunctorType()
1195 return SMESH::FT_RangeOfIds;
1199 Class : Comparator_i
1200 Description : Base class for comparators
1202 Comparator_i::Comparator_i():
1203 myNumericalFunctor( NULL )
1206 Comparator_i::~Comparator_i()
1208 if ( myNumericalFunctor )
1209 myNumericalFunctor->Destroy();
1212 void Comparator_i::SetMargin( CORBA::Double theValue )
1214 myComparatorPtr->SetMargin( theValue );
1215 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1218 CORBA::Double Comparator_i::GetMargin()
1220 return myComparatorPtr->GetMargin();
1223 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1225 if ( myNumericalFunctor )
1226 myNumericalFunctor->Destroy();
1228 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1230 if ( myNumericalFunctor )
1232 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1233 myNumericalFunctor->Register();
1234 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1238 Controls::ComparatorPtr Comparator_i::GetComparator()
1240 return myComparatorPtr;
1243 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1245 return myNumericalFunctor;
1251 Description : Comparator "<"
1253 LessThan_i::LessThan_i()
1255 myComparatorPtr.reset( new Controls::LessThan() );
1256 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1259 FunctorType LessThan_i::GetFunctorType()
1261 return SMESH::FT_LessThan;
1267 Description : Comparator ">"
1269 MoreThan_i::MoreThan_i()
1271 myComparatorPtr.reset( new Controls::MoreThan() );
1272 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1275 FunctorType MoreThan_i::GetFunctorType()
1277 return SMESH::FT_MoreThan;
1283 Description : Comparator "="
1285 EqualTo_i::EqualTo_i()
1286 : myEqualToPtr( new Controls::EqualTo() )
1288 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1291 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1293 myEqualToPtr->SetTolerance( theToler );
1294 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1297 CORBA::Double EqualTo_i::GetTolerance()
1299 return myEqualToPtr->GetTolerance();
1302 FunctorType EqualTo_i::GetFunctorType()
1304 return SMESH::FT_EqualTo;
1308 Class : LogicalNOT_i
1309 Description : Logical NOT predicate
1311 LogicalNOT_i::LogicalNOT_i()
1312 : myPredicate( NULL ),
1313 myLogicalNOTPtr( new Controls::LogicalNOT() )
1315 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1318 LogicalNOT_i::~LogicalNOT_i()
1321 myPredicate->Destroy();
1324 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1327 myPredicate->Destroy();
1329 myPredicate = SMESH::GetPredicate(thePredicate);
1332 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1333 myPredicate->Register();
1334 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1338 FunctorType LogicalNOT_i::GetFunctorType()
1340 return SMESH::FT_LogicalNOT;
1343 Predicate_i* LogicalNOT_i::GetPredicate_i()
1350 Class : LogicalBinary_i
1351 Description : Base class for binary logical predicate
1353 LogicalBinary_i::LogicalBinary_i()
1354 : myPredicate1( NULL ),
1355 myPredicate2( NULL )
1358 LogicalBinary_i::~LogicalBinary_i()
1361 myPredicate1->Destroy();
1364 myPredicate2->Destroy();
1367 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1370 myPredicate1->SetMesh( theMesh );
1373 myPredicate2->SetMesh( theMesh );
1376 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1379 myPredicate1->Destroy();
1381 myPredicate1 = SMESH::GetPredicate(thePredicate);
1383 if ( myPredicate1 ){
1384 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1385 myPredicate1->Register();
1386 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1390 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1393 myPredicate2->Destroy();
1395 myPredicate2 = SMESH::GetPredicate(thePredicate);
1397 if ( myPredicate2 ){
1398 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1399 myPredicate2->Register();
1400 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1404 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1406 return myLogicalBinaryPtr;
1409 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1411 return myPredicate1;
1413 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1415 return myPredicate2;
1420 Class : LogicalAND_i
1421 Description : Logical AND
1423 LogicalAND_i::LogicalAND_i()
1425 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1426 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1429 FunctorType LogicalAND_i::GetFunctorType()
1431 return SMESH::FT_LogicalAND;
1437 Description : Logical OR
1439 LogicalOR_i::LogicalOR_i()
1441 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1442 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1445 FunctorType LogicalOR_i::GetFunctorType()
1447 return SMESH::FT_LogicalOR;
1455 FilterManager_i::FilterManager_i()
1456 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1458 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
1459 //PortableServer::ObjectId_var anObjectId =
1460 // SMESH_Gen_i::GetPOA()->activate_object( this );
1464 FilterManager_i::~FilterManager_i()
1466 //TPythonDump()<<this<<".Destroy()";
1470 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1472 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1473 SMESH::MinimumAngle_var anObj = aServant->_this();
1474 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1475 return anObj._retn();
1479 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1481 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1482 SMESH::AspectRatio_var anObj = aServant->_this();
1483 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1484 return anObj._retn();
1488 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1490 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1491 SMESH::AspectRatio3D_var anObj = aServant->_this();
1492 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1493 return anObj._retn();
1497 Warping_ptr FilterManager_i::CreateWarping()
1499 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1500 SMESH::Warping_var anObj = aServant->_this();
1501 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1502 return anObj._retn();
1506 Taper_ptr FilterManager_i::CreateTaper()
1508 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1509 SMESH::Taper_var anObj = aServant->_this();
1510 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1511 return anObj._retn();
1515 Skew_ptr FilterManager_i::CreateSkew()
1517 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1518 SMESH::Skew_var anObj = aServant->_this();
1519 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1520 return anObj._retn();
1524 Area_ptr FilterManager_i::CreateArea()
1526 SMESH::Area_i* aServant = new SMESH::Area_i();
1527 SMESH::Area_var anObj = aServant->_this();
1528 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1529 return anObj._retn();
1533 Volume3D_ptr FilterManager_i::CreateVolume3D()
1535 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
1536 SMESH::Volume3D_var anObj = aServant->_this();
1537 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
1538 return anObj._retn();
1542 Length_ptr FilterManager_i::CreateLength()
1544 SMESH::Length_i* aServant = new SMESH::Length_i();
1545 SMESH::Length_var anObj = aServant->_this();
1546 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1547 return anObj._retn();
1550 Length2D_ptr FilterManager_i::CreateLength2D()
1552 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1553 SMESH::Length2D_var anObj = aServant->_this();
1554 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1555 return anObj._retn();
1558 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1560 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1561 SMESH::MultiConnection_var anObj = aServant->_this();
1562 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1563 return anObj._retn();
1566 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1568 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1569 SMESH::MultiConnection2D_var anObj = aServant->_this();
1570 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
1571 return anObj._retn();
1574 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1576 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1577 SMESH::BelongToGeom_var anObj = aServant->_this();
1578 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
1579 return anObj._retn();
1582 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1584 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1585 SMESH::BelongToPlane_var anObj = aServant->_this();
1586 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
1587 return anObj._retn();
1590 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1592 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1593 SMESH::BelongToCylinder_var anObj = aServant->_this();
1594 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
1595 return anObj._retn();
1598 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
1600 SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
1601 SMESH::BelongToGenSurface_var anObj = aServant->_this();
1602 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
1603 return anObj._retn();
1606 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
1608 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
1609 SMESH::LyingOnGeom_var anObj = aServant->_this();
1610 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
1611 return anObj._retn();
1614 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1616 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1617 SMESH::FreeBorders_var anObj = aServant->_this();
1618 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
1619 return anObj._retn();
1622 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1624 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1625 SMESH::FreeEdges_var anObj = aServant->_this();
1626 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
1627 return anObj._retn();
1630 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1632 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1633 SMESH::RangeOfIds_var anObj = aServant->_this();
1634 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
1635 return anObj._retn();
1638 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
1640 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
1641 SMESH::BadOrientedVolume_var anObj = aServant->_this();
1642 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
1643 return anObj._retn();
1646 LessThan_ptr FilterManager_i::CreateLessThan()
1648 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1649 SMESH::LessThan_var anObj = aServant->_this();
1650 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
1651 return anObj._retn();
1655 MoreThan_ptr FilterManager_i::CreateMoreThan()
1657 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1658 SMESH::MoreThan_var anObj = aServant->_this();
1659 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
1660 return anObj._retn();
1663 EqualTo_ptr FilterManager_i::CreateEqualTo()
1665 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1666 SMESH::EqualTo_var anObj = aServant->_this();
1667 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
1668 return anObj._retn();
1672 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1674 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1675 SMESH::LogicalNOT_var anObj = aServant->_this();
1676 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
1677 return anObj._retn();
1681 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
1683 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
1684 SMESH::LogicalAND_var anObj = aServant->_this();
1685 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
1686 return anObj._retn();
1690 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
1692 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
1693 SMESH::LogicalOR_var anObj = aServant->_this();
1694 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
1695 return anObj._retn();
1698 Filter_ptr FilterManager_i::CreateFilter()
1700 SMESH::Filter_i* aServant = new SMESH::Filter_i();
1701 SMESH::Filter_var anObj = aServant->_this();
1702 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
1703 return anObj._retn();
1706 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
1708 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
1709 SMESH::FilterLibrary_var anObj = aServant->_this();
1710 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary("<<aFileName<<")";
1711 return anObj._retn();
1714 FilterLibrary_ptr FilterManager_i::CreateLibrary()
1716 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
1717 SMESH::FilterLibrary_var anObj = aServant->_this();
1718 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
1719 return anObj._retn();
1722 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
1724 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
1725 return remove( aFileName ) ? false : true;
1728 //=============================================================================
1730 * SMESH_Gen_i::CreateFilterManager
1732 * Create filter manager
1734 //=============================================================================
1736 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
1738 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1739 SMESH::FilterManager_var anObj = aFilter->_this();
1740 return anObj._retn();
1748 //=======================================================================
1749 // name : Filter_i::Filter_i
1750 // Purpose : Constructor
1751 //=======================================================================
1752 Filter_i::Filter_i()
1753 : myPredicate( NULL )
1756 //=======================================================================
1757 // name : Filter_i::~Filter_i
1758 // Purpose : Destructor
1759 //=======================================================================
1760 Filter_i::~Filter_i()
1763 myPredicate->Destroy();
1765 if(!CORBA::is_nil(myMesh))
1768 //TPythonDump()<<this<<".Destroy()";
1771 //=======================================================================
1772 // name : Filter_i::SetPredicate
1773 // Purpose : Set predicate
1774 //=======================================================================
1775 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
1778 myPredicate->Destroy();
1780 myPredicate = SMESH::GetPredicate(thePredicate);
1784 myFilter.SetPredicate( myPredicate->GetPredicate() );
1785 myPredicate->Register();
1786 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1790 //=======================================================================
1791 // name : Filter_i::GetElementType
1792 // Purpose : Get entity type
1793 //=======================================================================
1794 SMESH::ElementType Filter_i::GetElementType()
1796 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
1799 //=======================================================================
1800 // name : Filter_i::SetMesh
1801 // Purpose : Set mesh
1802 //=======================================================================
1805 SetMesh( SMESH_Mesh_ptr theMesh )
1807 if(!CORBA::is_nil(theMesh))
1808 theMesh->Register();
1810 if(!CORBA::is_nil(myMesh))
1814 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
1821 return GetElementsId(myMesh);
1824 //=======================================================================
1825 // name : Filter_i::GetElementsId
1826 // Purpose : Get ids of entities
1827 //=======================================================================
1830 GetElementsId( Predicate_i* thePredicate,
1831 const SMDS_Mesh* theMesh,
1832 Controls::Filter::TIdSequence& theSequence )
1835 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
1840 GetElementsId( Predicate_i* thePredicate,
1841 SMESH_Mesh_ptr theMesh,
1842 Controls::Filter::TIdSequence& theSequence )
1845 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
1846 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
1851 GetElementsId( SMESH_Mesh_ptr theMesh )
1853 SMESH::long_array_var anArray = new SMESH::long_array;
1854 if(!CORBA::is_nil(theMesh) && myPredicate){
1855 Controls::Filter::TIdSequence aSequence;
1856 GetElementsId(myPredicate,theMesh,aSequence);
1857 long i = 0, iEnd = aSequence.size();
1858 anArray->length( iEnd );
1859 for ( ; i < iEnd; i++ )
1860 anArray[ i ] = aSequence[i];
1862 return anArray._retn();
1865 //=======================================================================
1866 // name : getCriteria
1867 // Purpose : Retrieve criterions from predicate
1868 //=======================================================================
1869 static inline bool getCriteria( Predicate_i* thePred,
1870 SMESH::Filter::Criteria_out theCriteria )
1872 int aFType = thePred->GetFunctorType();
1876 case FT_FreeBorders:
1879 CORBA::ULong i = theCriteria->length();
1880 theCriteria->length( i + 1 );
1882 theCriteria[ i ] = createCriterion();
1884 theCriteria[ i ].Type = aFType;
1885 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
1888 case FT_BelongToGeom:
1890 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
1892 CORBA::ULong i = theCriteria->length();
1893 theCriteria->length( i + 1 );
1895 theCriteria[ i ] = createCriterion();
1897 theCriteria[ i ].Type = FT_BelongToGeom;
1898 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1899 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1900 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1904 case FT_BelongToPlane:
1905 case FT_BelongToCylinder:
1906 case FT_BelongToGenSurface:
1908 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
1910 CORBA::ULong i = theCriteria->length();
1911 theCriteria->length( i + 1 );
1913 theCriteria[ i ] = createCriterion();
1915 theCriteria[ i ].Type = aFType;
1916 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1917 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1918 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1919 theCriteria[ i ].Tolerance = aPred->GetTolerance();
1923 case FT_LyingOnGeom:
1925 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
1927 CORBA::ULong i = theCriteria->length();
1928 theCriteria->length( i + 1 );
1930 theCriteria[ i ] = createCriterion();
1932 theCriteria[ i ].Type = FT_LyingOnGeom;
1933 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1934 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1935 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1941 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
1943 CORBA::ULong i = theCriteria->length();
1944 theCriteria->length( i + 1 );
1946 theCriteria[ i ] = createCriterion();
1948 theCriteria[ i ].Type = FT_RangeOfIds;
1949 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
1950 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1954 case FT_BadOrientedVolume:
1956 BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
1958 CORBA::ULong i = theCriteria->length();
1959 theCriteria->length( i + 1 );
1961 theCriteria[ i ] = createCriterion();
1963 theCriteria[ i ].Type = FT_BadOrientedVolume;
1964 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1972 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
1974 CORBA::ULong i = theCriteria->length();
1975 theCriteria->length( i + 1 );
1977 theCriteria[ i ] = createCriterion();
1979 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
1980 theCriteria[ i ].Compare = aFType;
1981 theCriteria[ i ].Threshold = aCompar->GetMargin();
1982 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
1984 if ( aFType == FT_EqualTo )
1986 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
1987 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
1994 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
1995 getCriteria( aPred, theCriteria );
1996 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2003 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2004 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2005 if ( !getCriteria( aPred1, theCriteria ) )
2007 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2008 return getCriteria( aPred2, theCriteria );
2018 //=======================================================================
2019 // name : Filter_i::GetCriteria
2020 // Purpose : Retrieve criterions from predicate
2021 //=======================================================================
2022 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2024 theCriteria = new SMESH::Filter::Criteria;
2025 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2028 //=======================================================================
2029 // name : Filter_i::SetCriteria
2030 // Purpose : Create new predicate and set criterions in it
2031 //=======================================================================
2032 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2034 if ( myPredicate != 0 )
2035 myPredicate->Destroy();
2037 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2038 FilterManager_ptr aFilterMgr = aFilter->_this();
2040 // CREATE two lists ( PREDICATES and LOG OP )
2043 TPythonDump()<<"aCriteria = []";
2044 std::list<SMESH::Predicate_ptr> aPredicates;
2045 std::list<int> aBinaries;
2046 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2048 int aCriterion = theCriteria[ i ].Type;
2049 int aCompare = theCriteria[ i ].Compare;
2050 double aThreshold = theCriteria[ i ].Threshold;
2051 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2052 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2053 int aUnary = theCriteria[ i ].UnaryOp;
2054 int aBinary = theCriteria[ i ].BinaryOp;
2055 double aTolerance = theCriteria[ i ].Tolerance;
2056 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
2057 long aPrecision = theCriteria[ i ].Precision;
2061 pd << "aCriterion = SMESH.Filter.Criterion(" << aCriterion << "," << aCompare
2062 << "," << aThreshold << ",'" << aThresholdStr;
2064 pd << "',salome.ObjectToID(" << aThresholdID
2065 << ")," << aUnary << "," << aBinary << "," << aTolerance
2066 << "," << aTypeOfElem << "," << aPrecision << ")";
2068 pd << "',''," << aUnary << "," << aBinary << "," << aTolerance
2069 << "," << aTypeOfElem << "," << aPrecision << ")";
2072 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2073 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2075 switch ( aCriterion )
2079 case SMESH::FT_MultiConnection:
2080 aFunctor = aFilterMgr->CreateMultiConnection();
2082 case SMESH::FT_MultiConnection2D:
2083 aFunctor = aFilterMgr->CreateMultiConnection2D();
2085 case SMESH::FT_Length:
2086 aFunctor = aFilterMgr->CreateLength();
2088 case SMESH::FT_Length2D:
2089 aFunctor = aFilterMgr->CreateLength2D();
2091 case SMESH::FT_AspectRatio:
2092 aFunctor = aFilterMgr->CreateAspectRatio();
2094 case SMESH::FT_AspectRatio3D:
2095 aFunctor = aFilterMgr->CreateAspectRatio3D();
2097 case SMESH::FT_Warping:
2098 aFunctor = aFilterMgr->CreateWarping();
2100 case SMESH::FT_MinimumAngle:
2101 aFunctor = aFilterMgr->CreateMinimumAngle();
2103 case SMESH::FT_Taper:
2104 aFunctor = aFilterMgr->CreateTaper();
2106 case SMESH::FT_Skew:
2107 aFunctor = aFilterMgr->CreateSkew();
2109 case SMESH::FT_Area:
2110 aFunctor = aFilterMgr->CreateArea();
2112 case SMESH::FT_Volume3D:
2113 aFunctor = aFilterMgr->CreateVolume3D();
2118 case SMESH::FT_FreeBorders:
2119 aPredicate = aFilterMgr->CreateFreeBorders();
2121 case SMESH::FT_FreeEdges:
2122 aPredicate = aFilterMgr->CreateFreeEdges();
2124 case SMESH::FT_BelongToGeom:
2126 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2127 tmpPred->SetElementType( aTypeOfElem );
2128 tmpPred->SetShape( aThresholdID, aThresholdStr );
2129 aPredicate = tmpPred;
2132 case SMESH::FT_BelongToPlane:
2133 case SMESH::FT_BelongToCylinder:
2134 case SMESH::FT_BelongToGenSurface:
2136 SMESH::BelongToSurface_ptr tmpPred;
2137 switch ( aCriterion ) {
2138 case SMESH::FT_BelongToPlane:
2139 tmpPred = aFilterMgr->CreateBelongToPlane(); break;
2140 case SMESH::FT_BelongToCylinder:
2141 tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
2143 tmpPred = aFilterMgr->CreateBelongToGenSurface();
2145 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2146 tmpPred->SetTolerance( aTolerance );
2147 aPredicate = tmpPred;
2150 case SMESH::FT_LyingOnGeom:
2152 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2153 tmpPred->SetElementType( aTypeOfElem );
2154 tmpPred->SetShape( aThresholdID, aThresholdStr );
2155 aPredicate = tmpPred;
2158 case SMESH::FT_RangeOfIds:
2160 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2161 tmpPred->SetRangeStr( aThresholdStr );
2162 tmpPred->SetElementType( aTypeOfElem );
2163 aPredicate = tmpPred;
2166 case SMESH::FT_BadOrientedVolume:
2168 aPredicate = aFilterMgr->CreateBadOrientedVolume();
2177 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
2179 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
2181 if ( aCompare == SMESH::FT_LessThan )
2182 aComparator = aFilterMgr->CreateLessThan();
2183 else if ( aCompare == SMESH::FT_MoreThan )
2184 aComparator = aFilterMgr->CreateMoreThan();
2185 else if ( aCompare == SMESH::FT_EqualTo )
2186 aComparator = aFilterMgr->CreateEqualTo();
2190 aComparator->SetNumFunctor( aFunctor );
2191 aComparator->SetMargin( aThreshold );
2193 if ( aCompare == FT_EqualTo )
2195 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
2196 anEqualTo->SetTolerance( aTolerance );
2199 aPredicate = aComparator;
2201 aFunctor->SetPrecision( aPrecision );
2205 if ( aUnary == FT_LogicalNOT )
2207 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
2208 aNotPred->SetPredicate( aPredicate );
2209 aPredicate = aNotPred;
2213 aPredicates.push_back( aPredicate );
2214 aBinaries.push_back( aBinary );
2215 TPythonDump()<<"aCriteria.append(aCriterion)";
2218 TPythonDump()<<this<<".SetCriteria(aCriteria)";
2220 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
2222 // combine all "AND" operations
2224 std::list<SMESH::Predicate_ptr> aResList;
2226 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
2227 std::list<int>::iterator aBinaryIter;
2229 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
2230 int aPrevBinary = SMESH::FT_Undefined;
2232 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
2233 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
2234 ++aPredIter, ++aBinaryIter )
2236 int aCurrBinary = *aBinaryIter;
2238 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
2240 if ( aPrevBinary == SMESH::FT_LogicalAND )
2243 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2244 aBinaryPred->SetPredicate1( aPrevPredicate );
2245 aBinaryPred->SetPredicate2( *aPredIter );
2246 aCurrPred = aBinaryPred;
2249 aCurrPred = *aPredIter;
2251 if ( aCurrBinary != SMESH::FT_LogicalAND )
2252 aResList.push_back( aCurrPred );
2254 aPrevPredicate = aCurrPred;
2255 aPrevBinary = aCurrBinary;
2258 // combine all "OR" operations
2260 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2262 if ( aResList.size() == 1 )
2263 aResPredicate = *aResList.begin();
2264 else if ( aResList.size() > 1 )
2266 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2267 aResPredicate = *anIter;
2269 for ( ; anIter != aResList.end(); ++anIter )
2271 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2272 aBinaryPred->SetPredicate1( aResPredicate );
2273 aBinaryPred->SetPredicate2( *anIter );
2274 aResPredicate = aBinaryPred;
2278 SetPredicate( aResPredicate );
2280 return !aResPredicate->_is_nil();
2283 //=======================================================================
2284 // name : Filter_i::GetPredicate_i
2285 // Purpose : Get implementation of predicate
2286 //=======================================================================
2287 Predicate_i* Filter_i::GetPredicate_i()
2292 //=======================================================================
2293 // name : Filter_i::GetPredicate
2294 // Purpose : Get predicate
2295 //=======================================================================
2296 Predicate_ptr Filter_i::GetPredicate()
2298 if ( myPredicate == 0 )
2299 return SMESH::Predicate::_nil();
2302 SMESH::Predicate_var anObj = myPredicate->_this();
2303 return anObj._retn();
2311 #define ATTR_TYPE "type"
2312 #define ATTR_COMPARE "compare"
2313 #define ATTR_THRESHOLD "threshold"
2314 #define ATTR_UNARY "unary"
2315 #define ATTR_BINARY "binary"
2316 #define ATTR_THRESHOLD_STR "threshold_str"
2317 #define ATTR_TOLERANCE "tolerance"
2318 #define ATTR_ELEMENT_TYPE "ElementType"
2320 //=======================================================================
2322 // Purpose : Convert bool to LDOMString
2323 //=======================================================================
2324 static inline LDOMString toString( CORBA::Boolean val )
2326 return val ? "logical not" : "";
2329 //=======================================================================
2331 // Purpose : Convert LDOMString to bool
2332 //=======================================================================
2333 static inline bool toBool( const LDOMString& theStr )
2335 return theStr.equals( "logical not" );
2338 //=======================================================================
2340 // Purpose : Convert double to LDOMString
2341 //=======================================================================
2342 static inline LDOMString toString( CORBA::Double val )
2345 sprintf( a, "%e", val );
2346 return LDOMString( a );
2349 //=======================================================================
2351 // Purpose : Convert LDOMString to double
2352 //=======================================================================
2353 static inline double toDouble( const LDOMString& theStr )
2355 return atof( theStr.GetString() );
2358 //=======================================================================
2360 // Purpose : Convert functor type to LDOMString
2361 //=======================================================================
2362 static inline LDOMString toString( CORBA::Long theType )
2366 case FT_AspectRatio : return "Aspect ratio";
2367 case FT_Warping : return "Warping";
2368 case FT_MinimumAngle : return "Minimum angle";
2369 case FT_Taper : return "Taper";
2370 case FT_Skew : return "Skew";
2371 case FT_Area : return "Area";
2372 case FT_Volume3D : return "Volume3D";
2373 case FT_BelongToGeom : return "Belong to Geom";
2374 case FT_BelongToPlane : return "Belong to Plane";
2375 case FT_BelongToCylinder: return "Belong to Cylinder";
2376 case FT_BelongToGenSurface: return "Belong to Generic Surface";
2377 case FT_LyingOnGeom : return "Lying on Geom";
2378 case FT_BadOrientedVolume: return "Bad Oriented Volume";
2379 case FT_RangeOfIds : return "Range of IDs";
2380 case FT_FreeBorders : return "Free borders";
2381 case FT_FreeEdges : return "Free edges";
2382 case FT_MultiConnection : return "Borders at multi-connections";
2383 case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2384 case FT_Length : return "Length";
2385 case FT_Length2D : return "Length2D";
2386 case FT_LessThan : return "Less than";
2387 case FT_MoreThan : return "More than";
2388 case FT_EqualTo : return "Equal to";
2389 case FT_LogicalNOT : return "Not";
2390 case FT_LogicalAND : return "And";
2391 case FT_LogicalOR : return "Or";
2392 case FT_Undefined : return "";
2393 default : return "";
2397 //=======================================================================
2398 // name : toFunctorType
2399 // Purpose : Convert LDOMString to functor type
2400 //=======================================================================
2401 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
2403 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
2404 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
2405 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
2406 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
2407 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
2408 else if ( theStr.equals( "Area" ) ) return FT_Area;
2409 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
2410 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
2411 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
2412 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
2413 else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface;
2414 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
2415 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
2416 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
2417 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
2418 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
2419 else if ( theStr.equals( "Length" ) ) return FT_Length;
2420 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
2421 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
2422 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
2423 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
2424 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
2425 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
2426 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
2427 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
2428 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
2429 else if ( theStr.equals( "" ) ) return FT_Undefined;
2430 else return FT_Undefined;
2433 //=======================================================================
2434 // name : toFunctorType
2435 // Purpose : Convert LDOMString to value of ElementType enumeration
2436 //=======================================================================
2437 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
2439 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
2440 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
2441 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
2442 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
2443 else return SMESH::ALL;
2446 //=======================================================================
2448 // Purpose : Convert ElementType to string
2449 //=======================================================================
2450 static inline LDOMString toString( const SMESH::ElementType theType )
2454 case SMESH::NODE : return "NODE";
2455 case SMESH::EDGE : return "EDGE";
2456 case SMESH::FACE : return "FACE";
2457 case SMESH::VOLUME : return "VOLUME";
2458 case SMESH::ALL : return "ALL";
2459 default : return "";
2463 //=======================================================================
2464 // name : findFilter
2465 // Purpose : Find filter in document
2466 //=======================================================================
2467 static LDOM_Element findFilter( const char* theFilterName,
2468 const LDOM_Document& theDoc,
2469 LDOM_Node* theParent = 0 )
2471 LDOM_Element aRootElement = theDoc.getDocumentElement();
2472 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
2473 return LDOM_Element();
2475 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
2476 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
2478 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
2479 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2481 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
2482 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
2483 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
2485 if ( theParent != 0 )
2486 *theParent = aTypeNode;
2487 return (LDOM_Element&)aFilter;
2491 return LDOM_Element();
2494 //=======================================================================
2495 // name : getSectionName
2496 // Purpose : Get name of section of filters
2497 //=======================================================================
2498 static const char* getSectionName( const ElementType theType )
2502 case SMESH::NODE : return "Filters for nodes";
2503 case SMESH::EDGE : return "Filters for edges";
2504 case SMESH::FACE : return "Filters for faces";
2505 case SMESH::VOLUME : return "Filters for volumes";
2506 case SMESH::ALL : return "Filters for elements";
2507 default : return "";
2511 //=======================================================================
2512 // name : getSection
2513 // Purpose : Create section for filters corresponding to the entity type
2514 //=======================================================================
2515 static LDOM_Node getSection( const ElementType theType,
2516 LDOM_Document& theDoc,
2517 const bool toCreate = false )
2519 LDOM_Element aRootElement = theDoc.getDocumentElement();
2520 if ( aRootElement.isNull() )
2524 bool anExist = false;
2525 const char* aSectionName = getSectionName( theType );
2526 if ( strcmp( aSectionName, "" ) == 0 )
2529 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
2531 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
2533 aNode = aSections.item( i );
2534 LDOM_Element& anItem = ( LDOM_Element& )aNode;
2535 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
2542 // Create new section if necessary
2547 LDOM_Element aNewItem = theDoc.createElement( "section" );
2548 aNewItem.setAttribute( "name", aSectionName );
2549 aRootElement.appendChild( aNewItem );
2559 //=======================================================================
2560 // name : createFilterItem
2561 // Purpose : Create filter item or LDOM document
2562 //=======================================================================
2563 static LDOM_Element createFilterItem( const char* theName,
2564 SMESH::Filter_ptr theFilter,
2565 LDOM_Document& theDoc )
2567 // create new filter in document
2568 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
2569 aFilterItem.setAttribute( "name", theName );
2571 // save filter criterions
2572 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2574 if ( !theFilter->GetCriteria( aCriteria ) )
2575 return LDOM_Element();
2577 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
2579 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
2581 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
2582 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
2583 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
2584 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
2585 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
2587 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
2588 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
2589 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
2590 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
2592 aFilterItem.appendChild( aCriterionItem );
2598 //=======================================================================
2599 // name : FilterLibrary_i::FilterLibrary_i
2600 // Purpose : Constructor
2601 //=======================================================================
2602 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
2604 myFileName = strdup( theFileName );
2605 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
2606 myFilterMgr = aFilterMgr->_this();
2610 // Try to use existing library file
2611 bool anExists = false;
2612 if ( !aParser.parse( myFileName ) )
2614 myDoc = aParser.getDocument();
2617 // Create a new XML document if it doesn't exist
2619 myDoc = LDOM_Document::createDocument( LDOMString() );
2621 LDOM_Element aRootElement = myDoc.getDocumentElement();
2622 if ( aRootElement.isNull() )
2624 // If the existing document is empty --> try to create a new one
2626 myDoc = LDOM_Document::createDocument( LDOMString() );
2630 //=======================================================================
2631 // name : FilterLibrary_i::FilterLibrary_i
2632 // Purpose : Constructor
2633 //=======================================================================
2634 FilterLibrary_i::FilterLibrary_i()
2637 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2638 myFilterMgr = aFilter->_this();
2640 myDoc = LDOM_Document::createDocument( LDOMString() );
2643 FilterLibrary_i::~FilterLibrary_i()
2646 //TPythonDump()<<this<<".Destroy()";
2649 //=======================================================================
2650 // name : FilterLibrary_i::Copy
2651 // Purpose : Create filter and initialize it with values from library
2652 //=======================================================================
2653 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
2655 Filter_ptr aRes = Filter::_nil();
2656 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
2658 if ( aFilter.isNull() )
2661 std::list<SMESH::Filter::Criterion> aCriteria;
2663 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
2664 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
2666 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
2668 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
2669 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
2670 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
2671 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
2672 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
2674 SMESH::Filter::Criterion aCriterion = createCriterion();
2676 aCriterion.Type = toFunctorType( aTypeStr );
2677 aCriterion.Compare = toFunctorType( aCompareStr );
2678 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
2679 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
2681 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
2683 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
2685 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2686 ? val : atof( str.GetString() );
2688 str = aCrit->getAttribute( ATTR_TOLERANCE );
2689 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2690 ? val : atof( str.GetString() );
2692 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
2693 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
2696 sprintf( a, "%d", val );
2697 aCriterion.ThresholdStr = strdup( a );
2700 aCriterion.ThresholdStr = str.GetString();
2702 aCriteria.push_back( aCriterion );
2705 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
2706 aCriteriaVar->length( aCriteria.size() );
2709 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
2711 for( ; anIter != aCriteria.end(); ++anIter )
2712 aCriteriaVar[ i++ ] = *anIter;
2714 aRes = myFilterMgr->CreateFilter();
2715 aRes->SetCriteria( aCriteriaVar.inout() );
2717 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
2722 //=======================================================================
2723 // name : FilterLibrary_i::SetFileName
2724 // Purpose : Set file name for library
2725 //=======================================================================
2726 void FilterLibrary_i::SetFileName( const char* theFileName )
2729 myFileName = strdup( theFileName );
2730 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
2733 //=======================================================================
2734 // name : FilterLibrary_i::GetFileName
2735 // Purpose : Get file name of library
2736 //=======================================================================
2737 char* FilterLibrary_i::GetFileName()
2739 return CORBA::string_dup( myFileName );
2742 //=======================================================================
2743 // name : FilterLibrary_i::Add
2744 // Purpose : Add new filter to library
2745 //=======================================================================
2746 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
2748 // if filter already in library or entry filter is null do nothing
2749 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2750 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
2753 // get section corresponding to the filter type
2754 ElementType anEntType = theFilter->GetElementType();
2756 LDOM_Node aSection = getSection( anEntType, myDoc, true );
2757 if ( aSection.isNull() )
2760 // create filter item
2761 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
2762 if ( aFilterItem.isNull() )
2766 aSection.appendChild( aFilterItem );
2767 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2768 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
2773 //=======================================================================
2774 // name : FilterLibrary_i::Add
2775 // Purpose : Add new filter to library
2776 //=======================================================================
2777 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
2779 // if filter already in library or entry filter is null do nothing
2780 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2781 if ( !aFilterNode.isNull() )
2784 LDOM_Node aSection = getSection( theType, myDoc, true );
2785 if ( aSection.isNull() )
2788 // create filter item
2789 Filter_var aFilter = myFilterMgr->CreateFilter();
2791 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
2792 if ( aFilterItem.isNull() )
2796 aSection.appendChild( aFilterItem );
2797 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
2802 //=======================================================================
2803 // name : FilterLibrary_i::Delete
2804 // Purpose : Delete filter from library
2805 //=======================================================================
2806 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
2808 LDOM_Node aParentNode;
2809 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
2810 if ( aFilterNode.isNull() || aParentNode.isNull() )
2813 aParentNode.removeChild( aFilterNode );
2814 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
2818 //=======================================================================
2819 // name : FilterLibrary_i::Replace
2820 // Purpose : Replace existing filter with entry filter.
2821 // IMPORTANT : If filter does not exist it is not created
2822 //=======================================================================
2823 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
2824 const char* theNewName,
2825 Filter_ptr theFilter )
2827 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
2828 if ( aFilterItem.isNull() || theFilter->_is_nil() )
2831 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
2832 if ( aNewItem.isNull() )
2836 aFilterItem.ReplaceElement( aNewItem );
2837 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2838 TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
2843 //=======================================================================
2844 // name : FilterLibrary_i::Save
2845 // Purpose : Save library on disk
2846 //=======================================================================
2847 CORBA::Boolean FilterLibrary_i::Save()
2849 if ( myFileName == 0 || strlen( myFileName ) == 0 )
2852 FILE* aOutFile = fopen( myFileName, "wt" );
2856 LDOM_XmlWriter aWriter( aOutFile );
2857 aWriter.SetIndentation( 2 );
2861 TPythonDump()<<this<<".Save()";
2865 //=======================================================================
2866 // name : FilterLibrary_i::SaveAs
2867 // Purpose : Save library on disk
2868 //=======================================================================
2869 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
2871 myFileName = strdup ( aFileName );
2872 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
2876 //=======================================================================
2877 // name : FilterLibrary_i::IsPresent
2878 // Purpose : Verify whether filter is in library
2879 //=======================================================================
2880 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
2882 return !findFilter( theFilterName, myDoc ).isNull();
2885 //=======================================================================
2886 // name : FilterLibrary_i::NbFilters
2887 // Purpose : Return amount of filters in library
2888 //=======================================================================
2889 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
2891 string_array_var aNames = GetNames( theType );
2892 return aNames->length();
2895 //=======================================================================
2896 // name : FilterLibrary_i::GetNames
2897 // Purpose : Get names of filters from library
2898 //=======================================================================
2899 string_array* FilterLibrary_i::GetNames( ElementType theType )
2901 string_array_var anArray = new string_array;
2902 TColStd_SequenceOfHAsciiString aSeq;
2904 LDOM_Node aSection = getSection( theType, myDoc, false );
2906 if ( !aSection.isNull() )
2908 for ( LDOM_Node aFilter = aSection.getFirstChild();
2909 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2911 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
2912 aSeq.Append( new TCollection_HAsciiString(
2913 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
2917 anArray->length( aSeq.Length() );
2918 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
2919 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
2921 return anArray._retn();
2924 //=======================================================================
2925 // name : FilterLibrary_i::GetAllNames
2926 // Purpose : Get names of filters from library
2927 //=======================================================================
2928 string_array* FilterLibrary_i::GetAllNames()
2930 string_array_var aResArray = new string_array;
2931 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
2933 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
2935 int aPrevLength = aResArray->length();
2936 aResArray->length( aPrevLength + aNames->length() );
2937 for ( int i = 0, n = aNames->length(); i < n; i++ )
2938 aResArray[ aPrevLength + i ] = aNames[ i ];
2941 return aResArray._retn();