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 PortableServer::ObjectId_var anObjectId =
455 SMESH_Gen_i::GetPOA()->activate_object( this );
458 Functor_i::~Functor_i()
460 //TPythonDump()<<this<<".Destroy()";
463 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
465 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
466 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
469 ElementType Functor_i::GetElementType()
471 return ( ElementType )myFunctorPtr->GetType();
476 Class : NumericalFunctor_i
477 Description : Base class for numerical functors
479 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
481 return myNumericalFunctorPtr->GetValue( theId );
484 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
486 myNumericalFunctorPtr->SetPrecision( thePrecision );
487 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
490 CORBA::Long NumericalFunctor_i::GetPrecision()
492 return myNumericalFunctorPtr->GetPrecision();
495 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
497 return myNumericalFunctorPtr;
502 Class : SMESH_MinimumAngle
503 Description : Functor for calculation of minimum angle
505 MinimumAngle_i::MinimumAngle_i()
507 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
508 myFunctorPtr = myNumericalFunctorPtr;
511 FunctorType MinimumAngle_i::GetFunctorType()
513 return SMESH::FT_MinimumAngle;
519 Description : Functor for calculating aspect ratio
521 AspectRatio_i::AspectRatio_i()
523 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
524 myFunctorPtr = myNumericalFunctorPtr;
527 FunctorType AspectRatio_i::GetFunctorType()
529 return SMESH::FT_AspectRatio;
534 Class : AspectRatio3D
535 Description : Functor for calculating aspect ratio 3D
537 AspectRatio3D_i::AspectRatio3D_i()
539 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
540 myFunctorPtr = myNumericalFunctorPtr;
543 FunctorType AspectRatio3D_i::GetFunctorType()
545 return SMESH::FT_AspectRatio3D;
551 Description : Functor for calculating warping
553 Warping_i::Warping_i()
555 myNumericalFunctorPtr.reset( new Controls::Warping() );
556 myFunctorPtr = myNumericalFunctorPtr;
559 FunctorType Warping_i::GetFunctorType()
561 return SMESH::FT_Warping;
567 Description : Functor for calculating taper
571 myNumericalFunctorPtr.reset( new Controls::Taper() );
572 myFunctorPtr = myNumericalFunctorPtr;
575 FunctorType Taper_i::GetFunctorType()
577 return SMESH::FT_Taper;
583 Description : Functor for calculating skew in degrees
587 myNumericalFunctorPtr.reset( new Controls::Skew() );
588 myFunctorPtr = myNumericalFunctorPtr;
591 FunctorType Skew_i::GetFunctorType()
593 return SMESH::FT_Skew;
598 Description : Functor for calculating area
602 myNumericalFunctorPtr.reset( new Controls::Area() );
603 myFunctorPtr = myNumericalFunctorPtr;
606 FunctorType Area_i::GetFunctorType()
608 return SMESH::FT_Area;
613 Description : Functor for calculating volume of 3D element
615 Volume3D_i::Volume3D_i()
617 myNumericalFunctorPtr.reset( new Controls::Volume() );
618 myFunctorPtr = myNumericalFunctorPtr;
621 FunctorType Volume3D_i::GetFunctorType()
623 return SMESH::FT_Volume3D;
628 Description : Functor for calculating length off edge
632 myNumericalFunctorPtr.reset( new Controls::Length() );
633 myFunctorPtr = myNumericalFunctorPtr;
636 FunctorType Length_i::GetFunctorType()
638 return SMESH::FT_Length;
643 Description : Functor for calculating length of edge
645 Length2D_i::Length2D_i()
647 myNumericalFunctorPtr.reset( new Controls::Length2D() );
648 myFunctorPtr = myNumericalFunctorPtr;
651 FunctorType Length2D_i::GetFunctorType()
653 return SMESH::FT_Length2D;
656 SMESH::Length2D::Values* Length2D_i::GetValues()
658 INFOS("Length2D_i::GetValues");
659 SMESH::Controls::Length2D::TValues aValues;
660 myLength2DPtr->GetValues( aValues );
662 long i = 0, iEnd = aValues.size();
664 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
666 SMESH::Controls::Length2D::TValues::const_iterator anIter;
667 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
669 const SMESH::Controls::Length2D::Value& aVal = *anIter;
670 SMESH::Length2D::Value &aValue = aResult[ i ];
672 aValue.myLength = aVal.myLength;
673 aValue.myPnt1 = aVal.myPntId[ 0 ];
674 aValue.myPnt2 = aVal.myPntId[ 1 ];
677 INFOS("Length2D_i::GetValuess~");
678 return aResult._retn();
682 Class : MultiConnection_i
683 Description : Functor for calculating number of faces conneted to the edge
685 MultiConnection_i::MultiConnection_i()
687 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
688 myFunctorPtr = myNumericalFunctorPtr;
691 FunctorType MultiConnection_i::GetFunctorType()
693 return SMESH::FT_MultiConnection;
697 Class : MultiConnection2D_i
698 Description : Functor for calculating number of faces conneted to the edge
700 MultiConnection2D_i::MultiConnection2D_i()
702 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
703 myFunctorPtr = myNumericalFunctorPtr;
706 FunctorType MultiConnection2D_i::GetFunctorType()
708 return SMESH::FT_MultiConnection2D;
711 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
713 INFOS("MultiConnection2D_i::GetValues");
714 SMESH::Controls::MultiConnection2D::MValues aValues;
715 myMulticonnection2DPtr->GetValues( aValues );
717 long i = 0, iEnd = aValues.size();
719 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
721 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
722 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
724 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
725 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
727 aValue.myPnt1 = aVal.myPntId[ 0 ];
728 aValue.myPnt2 = aVal.myPntId[ 1 ];
729 aValue.myNbConnects = (*anIter).second;
732 INFOS("Multiconnection2D_i::GetValuess~");
733 return aResult._retn();
743 Description : Base class for all predicates
745 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
747 return myPredicatePtr->IsSatisfy( theId );
750 Controls::PredicatePtr Predicate_i::GetPredicate()
752 return myPredicatePtr;
756 Class : BadOrientedVolume_i
757 Description : Verify whether a mesh volume is incorrectly oriented from
758 the point of view of MED convention
760 BadOrientedVolume_i::BadOrientedVolume_i()
762 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
763 myFunctorPtr = myPredicatePtr = control;
766 FunctorType BadOrientedVolume_i::GetFunctorType()
768 return SMESH::FT_BadOrientedVolume;
772 Class : BelongToGeom_i
773 Description : Predicate for selection on geometrical support
775 BelongToGeom_i::BelongToGeom_i()
777 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
778 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
783 BelongToGeom_i::~BelongToGeom_i()
789 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
791 if ( theGeom->_is_nil() )
793 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
794 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
795 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
796 myBelongToGeomPtr->SetGeom( aLocShape );
797 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
800 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
802 myBelongToGeomPtr->SetGeom( theShape );
805 void BelongToGeom_i::SetElementType(ElementType theType){
806 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
807 TPythonDump()<<this<<".SetElementType("<<theType<<")";
810 FunctorType BelongToGeom_i::GetFunctorType()
812 return SMESH::FT_BelongToGeom;
815 void BelongToGeom_i::SetShapeName( const char* theName )
818 myShapeName = strdup( theName );
819 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
820 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
823 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
826 myShapeName = strdup( theName );
829 myShapeID = strdup( theID );
833 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
834 myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
836 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
839 char* BelongToGeom_i::GetShapeName()
841 return CORBA::string_dup( myShapeName );
844 char* BelongToGeom_i::GetShapeID()
846 return CORBA::string_dup( myShapeID );
850 Class : BelongToSurface_i
851 Description : Predicate for selection on geometrical support
853 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
855 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
856 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
859 mySurfaceType = theSurfaceType;
862 BelongToSurface_i::~BelongToSurface_i()
868 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
870 if ( theGeom->_is_nil() )
872 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
873 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
874 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
876 if ( aLocShape.ShapeType() == TopAbs_FACE )
878 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
879 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
881 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
886 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
889 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
892 myShapeName = strdup( theName );
893 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
894 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
897 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
900 myShapeName = strdup( theName );
903 myShapeID = strdup( theID );
907 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
908 myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
910 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
913 char* BelongToSurface_i::GetShapeName()
915 return CORBA::string_dup( myShapeName );
918 char* BelongToSurface_i::GetShapeID()
920 return CORBA::string_dup( myShapeID );
923 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
925 myElementsOnSurfacePtr->SetTolerance( theToler );
926 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
929 CORBA::Double BelongToSurface_i::GetTolerance()
931 return myElementsOnSurfacePtr->GetTolerance();
934 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
936 myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
937 TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
940 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
942 return myElementsOnSurfacePtr->GetUseBoundaries();
947 Class : BelongToPlane_i
948 Description : Verify whether mesh element lie in pointed Geom planar object
951 BelongToPlane_i::BelongToPlane_i()
952 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
956 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
958 BelongToSurface_i::SetSurface( theGeom, theType );
959 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
962 FunctorType BelongToPlane_i::GetFunctorType()
964 return FT_BelongToPlane;
968 Class : BelongToCylinder_i
969 Description : Verify whether mesh element lie in pointed Geom planar object
972 BelongToCylinder_i::BelongToCylinder_i()
973 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
977 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
979 BelongToSurface_i::SetSurface( theGeom, theType );
980 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
983 FunctorType BelongToCylinder_i::GetFunctorType()
985 return FT_BelongToCylinder;
989 Class : BelongToGenSurface_i
990 Description : Verify whether mesh element lie in pointed Geom planar object
993 BelongToGenSurface_i::BelongToGenSurface_i()
994 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
998 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1000 if ( theGeom->_is_nil() )
1002 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1003 if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1004 aLocShape.Nullify();
1006 BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1007 TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1010 FunctorType BelongToGenSurface_i::GetFunctorType()
1012 return FT_BelongToGenSurface;
1016 Class : LyingOnGeom_i
1017 Description : Predicate for selection on geometrical support
1019 LyingOnGeom_i::LyingOnGeom_i()
1021 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1022 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1027 LyingOnGeom_i::~LyingOnGeom_i()
1033 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1035 if ( theGeom->_is_nil() )
1037 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1038 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1039 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1040 myLyingOnGeomPtr->SetGeom( aLocShape );
1041 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1044 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1046 myLyingOnGeomPtr->SetGeom( theShape );
1049 void LyingOnGeom_i::SetElementType(ElementType theType){
1050 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1051 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1054 FunctorType LyingOnGeom_i::GetFunctorType()
1056 return SMESH::FT_LyingOnGeom;
1059 void LyingOnGeom_i::SetShapeName( const char* theName )
1062 myShapeName = strdup( theName );
1063 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1064 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1067 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1070 myShapeName = strdup( theName );
1073 myShapeID = strdup( theID );
1077 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1078 myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
1080 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1083 char* LyingOnGeom_i::GetShapeName()
1085 return CORBA::string_dup( myShapeName );
1088 char* LyingOnGeom_i::GetShapeID()
1090 return CORBA::string_dup( myShapeID );
1094 Class : FreeBorders_i
1095 Description : Predicate for free borders
1097 FreeBorders_i::FreeBorders_i()
1099 myPredicatePtr.reset(new Controls::FreeBorders());
1100 myFunctorPtr = myPredicatePtr;
1103 FunctorType FreeBorders_i::GetFunctorType()
1105 return SMESH::FT_FreeBorders;
1110 Description : Predicate for free borders
1112 FreeEdges_i::FreeEdges_i()
1113 : myFreeEdgesPtr( new Controls::FreeEdges() )
1115 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1118 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1120 INFOS("FreeEdges_i::GetBorders");
1121 SMESH::Controls::FreeEdges::TBorders aBorders;
1122 myFreeEdgesPtr->GetBoreders( aBorders );
1124 long i = 0, iEnd = aBorders.size();
1126 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1127 aResult->length(iEnd);
1129 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1130 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1132 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1133 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1135 aBorder.myElemId = aBord.myElemId;
1136 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1137 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1140 INFOS("FreeEdges_i::GetBorders~");
1141 return aResult._retn();
1144 FunctorType FreeEdges_i::GetFunctorType()
1146 return SMESH::FT_FreeEdges;
1150 Class : RangeOfIds_i
1151 Description : Predicate for Range of Ids.
1152 Range may be specified with two ways.
1153 1. Using AddToRange method
1154 2. With SetRangeStr method. Parameter of this method is a string
1155 like as "1,2,3,50-60,63,67,70-"
1158 RangeOfIds_i::RangeOfIds_i()
1160 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1161 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1164 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1166 CORBA::Long iEnd = theIds.length();
1167 for ( CORBA::Long i = 0; i < iEnd; i++ )
1168 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1169 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1172 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1174 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1175 return myRangeOfIdsPtr->SetRangeStr(
1176 TCollection_AsciiString( (Standard_CString)theRange ) );
1179 char* RangeOfIds_i::GetRangeStr()
1181 TCollection_AsciiString aStr;
1182 myRangeOfIdsPtr->GetRangeStr( aStr );
1183 return CORBA::string_dup( aStr.ToCString() );
1186 void RangeOfIds_i::SetElementType( ElementType theType )
1188 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1189 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1192 FunctorType RangeOfIds_i::GetFunctorType()
1194 return SMESH::FT_RangeOfIds;
1198 Class : Comparator_i
1199 Description : Base class for comparators
1201 Comparator_i::Comparator_i():
1202 myNumericalFunctor( NULL )
1205 Comparator_i::~Comparator_i()
1207 if ( myNumericalFunctor )
1208 myNumericalFunctor->Destroy();
1211 void Comparator_i::SetMargin( CORBA::Double theValue )
1213 myComparatorPtr->SetMargin( theValue );
1214 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1217 CORBA::Double Comparator_i::GetMargin()
1219 return myComparatorPtr->GetMargin();
1222 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1224 if ( myNumericalFunctor )
1225 myNumericalFunctor->Destroy();
1227 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1229 if ( myNumericalFunctor )
1231 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1232 myNumericalFunctor->Register();
1233 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1237 Controls::ComparatorPtr Comparator_i::GetComparator()
1239 return myComparatorPtr;
1242 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1244 return myNumericalFunctor;
1250 Description : Comparator "<"
1252 LessThan_i::LessThan_i()
1254 myComparatorPtr.reset( new Controls::LessThan() );
1255 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1258 FunctorType LessThan_i::GetFunctorType()
1260 return SMESH::FT_LessThan;
1266 Description : Comparator ">"
1268 MoreThan_i::MoreThan_i()
1270 myComparatorPtr.reset( new Controls::MoreThan() );
1271 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1274 FunctorType MoreThan_i::GetFunctorType()
1276 return SMESH::FT_MoreThan;
1282 Description : Comparator "="
1284 EqualTo_i::EqualTo_i()
1285 : myEqualToPtr( new Controls::EqualTo() )
1287 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1290 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1292 myEqualToPtr->SetTolerance( theToler );
1293 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1296 CORBA::Double EqualTo_i::GetTolerance()
1298 return myEqualToPtr->GetTolerance();
1301 FunctorType EqualTo_i::GetFunctorType()
1303 return SMESH::FT_EqualTo;
1307 Class : LogicalNOT_i
1308 Description : Logical NOT predicate
1310 LogicalNOT_i::LogicalNOT_i()
1311 : myPredicate( NULL ),
1312 myLogicalNOTPtr( new Controls::LogicalNOT() )
1314 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1317 LogicalNOT_i::~LogicalNOT_i()
1320 myPredicate->Destroy();
1323 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1326 myPredicate->Destroy();
1328 myPredicate = SMESH::GetPredicate(thePredicate);
1331 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1332 myPredicate->Register();
1333 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1337 FunctorType LogicalNOT_i::GetFunctorType()
1339 return SMESH::FT_LogicalNOT;
1342 Predicate_i* LogicalNOT_i::GetPredicate_i()
1349 Class : LogicalBinary_i
1350 Description : Base class for binary logical predicate
1352 LogicalBinary_i::LogicalBinary_i()
1353 : myPredicate1( NULL ),
1354 myPredicate2( NULL )
1357 LogicalBinary_i::~LogicalBinary_i()
1360 myPredicate1->Destroy();
1363 myPredicate2->Destroy();
1366 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1369 myPredicate1->SetMesh( theMesh );
1372 myPredicate2->SetMesh( theMesh );
1375 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1378 myPredicate1->Destroy();
1380 myPredicate1 = SMESH::GetPredicate(thePredicate);
1382 if ( myPredicate1 ){
1383 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1384 myPredicate1->Register();
1385 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1389 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1392 myPredicate2->Destroy();
1394 myPredicate2 = SMESH::GetPredicate(thePredicate);
1396 if ( myPredicate2 ){
1397 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1398 myPredicate2->Register();
1399 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1403 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1405 return myLogicalBinaryPtr;
1408 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1410 return myPredicate1;
1412 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1414 return myPredicate2;
1419 Class : LogicalAND_i
1420 Description : Logical AND
1422 LogicalAND_i::LogicalAND_i()
1424 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1425 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1428 FunctorType LogicalAND_i::GetFunctorType()
1430 return SMESH::FT_LogicalAND;
1436 Description : Logical OR
1438 LogicalOR_i::LogicalOR_i()
1440 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1441 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1444 FunctorType LogicalOR_i::GetFunctorType()
1446 return SMESH::FT_LogicalOR;
1454 FilterManager_i::FilterManager_i()
1455 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1457 PortableServer::ObjectId_var anObjectId =
1458 SMESH_Gen_i::GetPOA()->activate_object( this );
1462 FilterManager_i::~FilterManager_i()
1464 //TPythonDump()<<this<<".Destroy()";
1468 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1470 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1471 SMESH::MinimumAngle_var anObj = aServant->_this();
1472 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1473 return anObj._retn();
1477 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1479 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1480 SMESH::AspectRatio_var anObj = aServant->_this();
1481 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1482 return anObj._retn();
1486 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1488 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1489 SMESH::AspectRatio3D_var anObj = aServant->_this();
1490 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1491 return anObj._retn();
1495 Warping_ptr FilterManager_i::CreateWarping()
1497 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1498 SMESH::Warping_var anObj = aServant->_this();
1499 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1500 return anObj._retn();
1504 Taper_ptr FilterManager_i::CreateTaper()
1506 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1507 SMESH::Taper_var anObj = aServant->_this();
1508 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1509 return anObj._retn();
1513 Skew_ptr FilterManager_i::CreateSkew()
1515 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1516 SMESH::Skew_var anObj = aServant->_this();
1517 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1518 return anObj._retn();
1522 Area_ptr FilterManager_i::CreateArea()
1524 SMESH::Area_i* aServant = new SMESH::Area_i();
1525 SMESH::Area_var anObj = aServant->_this();
1526 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1527 return anObj._retn();
1531 Volume3D_ptr FilterManager_i::CreateVolume3D()
1533 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
1534 SMESH::Volume3D_var anObj = aServant->_this();
1535 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
1536 return anObj._retn();
1540 Length_ptr FilterManager_i::CreateLength()
1542 SMESH::Length_i* aServant = new SMESH::Length_i();
1543 SMESH::Length_var anObj = aServant->_this();
1544 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1545 return anObj._retn();
1548 Length2D_ptr FilterManager_i::CreateLength2D()
1550 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1551 SMESH::Length2D_var anObj = aServant->_this();
1552 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1553 return anObj._retn();
1556 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1558 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1559 SMESH::MultiConnection_var anObj = aServant->_this();
1560 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1561 return anObj._retn();
1564 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1566 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1567 SMESH::MultiConnection2D_var anObj = aServant->_this();
1568 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
1569 return anObj._retn();
1572 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1574 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1575 SMESH::BelongToGeom_var anObj = aServant->_this();
1576 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
1577 return anObj._retn();
1580 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1582 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1583 SMESH::BelongToPlane_var anObj = aServant->_this();
1584 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
1585 return anObj._retn();
1588 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1590 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1591 SMESH::BelongToCylinder_var anObj = aServant->_this();
1592 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
1593 return anObj._retn();
1596 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
1598 SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
1599 SMESH::BelongToGenSurface_var anObj = aServant->_this();
1600 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
1601 return anObj._retn();
1604 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
1606 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
1607 SMESH::LyingOnGeom_var anObj = aServant->_this();
1608 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
1609 return anObj._retn();
1612 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1614 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1615 SMESH::FreeBorders_var anObj = aServant->_this();
1616 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
1617 return anObj._retn();
1620 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1622 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1623 SMESH::FreeEdges_var anObj = aServant->_this();
1624 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
1625 return anObj._retn();
1628 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1630 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1631 SMESH::RangeOfIds_var anObj = aServant->_this();
1632 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
1633 return anObj._retn();
1636 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
1638 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
1639 SMESH::BadOrientedVolume_var anObj = aServant->_this();
1640 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
1641 return anObj._retn();
1644 LessThan_ptr FilterManager_i::CreateLessThan()
1646 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1647 SMESH::LessThan_var anObj = aServant->_this();
1648 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
1649 return anObj._retn();
1653 MoreThan_ptr FilterManager_i::CreateMoreThan()
1655 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1656 SMESH::MoreThan_var anObj = aServant->_this();
1657 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
1658 return anObj._retn();
1661 EqualTo_ptr FilterManager_i::CreateEqualTo()
1663 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1664 SMESH::EqualTo_var anObj = aServant->_this();
1665 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
1666 return anObj._retn();
1670 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1672 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1673 SMESH::LogicalNOT_var anObj = aServant->_this();
1674 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
1675 return anObj._retn();
1679 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
1681 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
1682 SMESH::LogicalAND_var anObj = aServant->_this();
1683 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
1684 return anObj._retn();
1688 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
1690 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
1691 SMESH::LogicalOR_var anObj = aServant->_this();
1692 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
1693 return anObj._retn();
1696 Filter_ptr FilterManager_i::CreateFilter()
1698 SMESH::Filter_i* aServant = new SMESH::Filter_i();
1699 SMESH::Filter_var anObj = aServant->_this();
1700 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
1701 return anObj._retn();
1704 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
1706 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
1707 SMESH::FilterLibrary_var anObj = aServant->_this();
1708 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary("<<aFileName<<")";
1709 return anObj._retn();
1712 FilterLibrary_ptr FilterManager_i::CreateLibrary()
1714 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
1715 SMESH::FilterLibrary_var anObj = aServant->_this();
1716 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
1717 return anObj._retn();
1720 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
1722 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
1723 return remove( aFileName ) ? false : true;
1726 //=============================================================================
1728 * SMESH_Gen_i::CreateFilterManager
1730 * Create filter manager
1732 //=============================================================================
1734 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
1736 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1737 SMESH::FilterManager_var anObj = aFilter->_this();
1738 return anObj._retn();
1746 //=======================================================================
1747 // name : Filter_i::Filter_i
1748 // Purpose : Constructor
1749 //=======================================================================
1750 Filter_i::Filter_i()
1751 : myPredicate( NULL )
1754 //=======================================================================
1755 // name : Filter_i::~Filter_i
1756 // Purpose : Destructor
1757 //=======================================================================
1758 Filter_i::~Filter_i()
1761 myPredicate->Destroy();
1763 if(!CORBA::is_nil(myMesh))
1766 //TPythonDump()<<this<<".Destroy()";
1769 //=======================================================================
1770 // name : Filter_i::SetPredicate
1771 // Purpose : Set predicate
1772 //=======================================================================
1773 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
1776 myPredicate->Destroy();
1778 myPredicate = SMESH::GetPredicate(thePredicate);
1782 myFilter.SetPredicate( myPredicate->GetPredicate() );
1783 myPredicate->Register();
1784 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1788 //=======================================================================
1789 // name : Filter_i::GetElementType
1790 // Purpose : Get entity type
1791 //=======================================================================
1792 SMESH::ElementType Filter_i::GetElementType()
1794 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
1797 //=======================================================================
1798 // name : Filter_i::SetMesh
1799 // Purpose : Set mesh
1800 //=======================================================================
1803 SetMesh( SMESH_Mesh_ptr theMesh )
1805 if(!CORBA::is_nil(theMesh))
1806 theMesh->Register();
1808 if(!CORBA::is_nil(myMesh))
1812 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
1819 return GetElementsId(myMesh);
1822 //=======================================================================
1823 // name : Filter_i::GetElementsId
1824 // Purpose : Get ids of entities
1825 //=======================================================================
1828 GetElementsId( Predicate_i* thePredicate,
1829 const SMDS_Mesh* theMesh,
1830 Controls::Filter::TIdSequence& theSequence )
1832 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
1837 GetElementsId( Predicate_i* thePredicate,
1838 SMESH_Mesh_ptr theMesh,
1839 Controls::Filter::TIdSequence& theSequence )
1841 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
1842 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
1847 GetElementsId( SMESH_Mesh_ptr theMesh )
1849 SMESH::long_array_var anArray = new SMESH::long_array;
1850 if(!CORBA::is_nil(theMesh)){
1851 Controls::Filter::TIdSequence aSequence;
1852 GetElementsId(myPredicate,theMesh,aSequence);
1853 long i = 0, iEnd = aSequence.size();
1854 anArray->length( iEnd );
1855 for ( ; i < iEnd; i++ )
1856 anArray[ i ] = aSequence[i];
1858 return anArray._retn();
1861 //=======================================================================
1862 // name : getCriteria
1863 // Purpose : Retrieve criterions from predicate
1864 //=======================================================================
1865 static inline bool getCriteria( Predicate_i* thePred,
1866 SMESH::Filter::Criteria_out theCriteria )
1868 int aFType = thePred->GetFunctorType();
1872 case FT_FreeBorders:
1875 CORBA::ULong i = theCriteria->length();
1876 theCriteria->length( i + 1 );
1878 theCriteria[ i ] = createCriterion();
1880 theCriteria[ i ].Type = aFType;
1881 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
1884 case FT_BelongToGeom:
1886 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
1888 CORBA::ULong i = theCriteria->length();
1889 theCriteria->length( i + 1 );
1891 theCriteria[ i ] = createCriterion();
1893 theCriteria[ i ].Type = FT_BelongToGeom;
1894 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1895 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1896 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1900 case FT_BelongToPlane:
1901 case FT_BelongToCylinder:
1902 case FT_BelongToGenSurface:
1904 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
1906 CORBA::ULong i = theCriteria->length();
1907 theCriteria->length( i + 1 );
1909 theCriteria[ i ] = createCriterion();
1911 theCriteria[ i ].Type = aFType;
1912 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1913 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1914 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1915 theCriteria[ i ].Tolerance = aPred->GetTolerance();
1919 case FT_LyingOnGeom:
1921 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
1923 CORBA::ULong i = theCriteria->length();
1924 theCriteria->length( i + 1 );
1926 theCriteria[ i ] = createCriterion();
1928 theCriteria[ i ].Type = FT_LyingOnGeom;
1929 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1930 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1931 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1937 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
1939 CORBA::ULong i = theCriteria->length();
1940 theCriteria->length( i + 1 );
1942 theCriteria[ i ] = createCriterion();
1944 theCriteria[ i ].Type = FT_RangeOfIds;
1945 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
1946 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1950 case FT_BadOrientedVolume:
1952 BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
1954 CORBA::ULong i = theCriteria->length();
1955 theCriteria->length( i + 1 );
1957 theCriteria[ i ] = createCriterion();
1959 theCriteria[ i ].Type = FT_BadOrientedVolume;
1960 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1968 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
1970 CORBA::ULong i = theCriteria->length();
1971 theCriteria->length( i + 1 );
1973 theCriteria[ i ] = createCriterion();
1975 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
1976 theCriteria[ i ].Compare = aFType;
1977 theCriteria[ i ].Threshold = aCompar->GetMargin();
1978 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
1980 if ( aFType == FT_EqualTo )
1982 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
1983 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
1990 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
1991 getCriteria( aPred, theCriteria );
1992 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
1999 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2000 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2001 if ( !getCriteria( aPred1, theCriteria ) )
2003 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2004 return getCriteria( aPred2, theCriteria );
2014 //=======================================================================
2015 // name : Filter_i::GetCriteria
2016 // Purpose : Retrieve criterions from predicate
2017 //=======================================================================
2018 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2020 theCriteria = new SMESH::Filter::Criteria;
2021 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2024 //=======================================================================
2025 // name : Filter_i::SetCriteria
2026 // Purpose : Create new predicate and set criterions in it
2027 //=======================================================================
2028 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2030 if ( myPredicate != 0 )
2031 myPredicate->Destroy();
2033 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2034 FilterManager_ptr aFilterMgr = aFilter->_this();
2036 // CREATE two lists ( PREDICATES and LOG OP )
2039 TPythonDump()<<"aCriteria = []";
2040 std::list<SMESH::Predicate_ptr> aPredicates;
2041 std::list<int> aBinaries;
2042 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2044 int aCriterion = theCriteria[ i ].Type;
2045 int aCompare = theCriteria[ i ].Compare;
2046 double aThreshold = theCriteria[ i ].Threshold;
2047 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2048 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2049 int aUnary = theCriteria[ i ].UnaryOp;
2050 int aBinary = theCriteria[ i ].BinaryOp;
2051 double aTolerance = theCriteria[ i ].Tolerance;
2052 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
2053 long aPrecision = theCriteria[ i ].Precision;
2057 pd << "aCriterion = SMESH.Filter.Criterion(" << aCriterion << "," << aCompare
2058 << "," << aThreshold << ",'" << aThresholdStr;
2059 if (strlen(aThresholdID) > 0)
2060 pd << "',salome.ObjectToID(" << aThresholdID
2061 << ")," << aUnary << "," << aBinary << "," << aTolerance
2062 << "," << aTypeOfElem << "," << aPrecision << ")";
2064 pd << "',''," << aUnary << "," << aBinary << "," << aTolerance
2065 << "," << aTypeOfElem << "," << aPrecision << ")";
2068 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2069 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2071 switch ( aCriterion )
2075 case SMESH::FT_MultiConnection:
2076 aFunctor = aFilterMgr->CreateMultiConnection();
2078 case SMESH::FT_MultiConnection2D:
2079 aFunctor = aFilterMgr->CreateMultiConnection2D();
2081 case SMESH::FT_Length:
2082 aFunctor = aFilterMgr->CreateLength();
2084 case SMESH::FT_Length2D:
2085 aFunctor = aFilterMgr->CreateLength2D();
2087 case SMESH::FT_AspectRatio:
2088 aFunctor = aFilterMgr->CreateAspectRatio();
2090 case SMESH::FT_AspectRatio3D:
2091 aFunctor = aFilterMgr->CreateAspectRatio3D();
2093 case SMESH::FT_Warping:
2094 aFunctor = aFilterMgr->CreateWarping();
2096 case SMESH::FT_MinimumAngle:
2097 aFunctor = aFilterMgr->CreateMinimumAngle();
2099 case SMESH::FT_Taper:
2100 aFunctor = aFilterMgr->CreateTaper();
2102 case SMESH::FT_Skew:
2103 aFunctor = aFilterMgr->CreateSkew();
2105 case SMESH::FT_Area:
2106 aFunctor = aFilterMgr->CreateArea();
2108 case SMESH::FT_Volume3D:
2109 aFunctor = aFilterMgr->CreateVolume3D();
2114 case SMESH::FT_FreeBorders:
2115 aPredicate = aFilterMgr->CreateFreeBorders();
2117 case SMESH::FT_FreeEdges:
2118 aPredicate = aFilterMgr->CreateFreeEdges();
2120 case SMESH::FT_BelongToGeom:
2122 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2123 tmpPred->SetElementType( aTypeOfElem );
2124 tmpPred->SetShape( aThresholdID, aThresholdStr );
2125 aPredicate = tmpPred;
2128 case SMESH::FT_BelongToPlane:
2129 case SMESH::FT_BelongToCylinder:
2130 case SMESH::FT_BelongToGenSurface:
2132 SMESH::BelongToSurface_ptr tmpPred;
2133 switch ( aCriterion ) {
2134 case SMESH::FT_BelongToPlane:
2135 tmpPred = aFilterMgr->CreateBelongToPlane(); break;
2136 case SMESH::FT_BelongToCylinder:
2137 tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
2139 tmpPred = aFilterMgr->CreateBelongToGenSurface();
2141 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2142 tmpPred->SetTolerance( aTolerance );
2143 aPredicate = tmpPred;
2146 case SMESH::FT_LyingOnGeom:
2148 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2149 tmpPred->SetElementType( aTypeOfElem );
2150 tmpPred->SetShape( aThresholdID, aThresholdStr );
2151 aPredicate = tmpPred;
2154 case SMESH::FT_RangeOfIds:
2156 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2157 tmpPred->SetRangeStr( aThresholdStr );
2158 tmpPred->SetElementType( aTypeOfElem );
2159 aPredicate = tmpPred;
2162 case SMESH::FT_BadOrientedVolume:
2164 aPredicate = aFilterMgr->CreateBadOrientedVolume();
2173 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
2175 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
2177 if ( aCompare == SMESH::FT_LessThan )
2178 aComparator = aFilterMgr->CreateLessThan();
2179 else if ( aCompare == SMESH::FT_MoreThan )
2180 aComparator = aFilterMgr->CreateMoreThan();
2181 else if ( aCompare == SMESH::FT_EqualTo )
2182 aComparator = aFilterMgr->CreateEqualTo();
2186 aComparator->SetNumFunctor( aFunctor );
2187 aComparator->SetMargin( aThreshold );
2189 if ( aCompare == FT_EqualTo )
2191 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
2192 anEqualTo->SetTolerance( aTolerance );
2195 aPredicate = aComparator;
2197 aFunctor->SetPrecision( aPrecision );
2201 if ( aUnary == FT_LogicalNOT )
2203 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
2204 aNotPred->SetPredicate( aPredicate );
2205 aPredicate = aNotPred;
2209 aPredicates.push_back( aPredicate );
2210 aBinaries.push_back( aBinary );
2211 TPythonDump()<<"aCriteria.append(aCriterion)";
2214 TPythonDump()<<this<<".SetCriteria(aCriteria)";
2216 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
2218 // combine all "AND" operations
2220 std::list<SMESH::Predicate_ptr> aResList;
2222 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
2223 std::list<int>::iterator aBinaryIter;
2225 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
2226 int aPrevBinary = SMESH::FT_Undefined;
2228 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
2229 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
2230 ++aPredIter, ++aBinaryIter )
2232 int aCurrBinary = *aBinaryIter;
2234 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
2236 if ( aPrevBinary == SMESH::FT_LogicalAND )
2239 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2240 aBinaryPred->SetPredicate1( aPrevPredicate );
2241 aBinaryPred->SetPredicate2( *aPredIter );
2242 aCurrPred = aBinaryPred;
2245 aCurrPred = *aPredIter;
2247 if ( aCurrBinary != SMESH::FT_LogicalAND )
2248 aResList.push_back( aCurrPred );
2250 aPrevPredicate = aCurrPred;
2251 aPrevBinary = aCurrBinary;
2254 // combine all "OR" operations
2256 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2258 if ( aResList.size() == 1 )
2259 aResPredicate = *aResList.begin();
2260 else if ( aResList.size() > 1 )
2262 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2263 aResPredicate = *anIter;
2265 for ( ; anIter != aResList.end(); ++anIter )
2267 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2268 aBinaryPred->SetPredicate1( aResPredicate );
2269 aBinaryPred->SetPredicate2( *anIter );
2270 aResPredicate = aBinaryPred;
2274 SetPredicate( aResPredicate );
2276 return !aResPredicate->_is_nil();
2279 //=======================================================================
2280 // name : Filter_i::GetPredicate_i
2281 // Purpose : Get implementation of predicate
2282 //=======================================================================
2283 Predicate_i* Filter_i::GetPredicate_i()
2288 //=======================================================================
2289 // name : Filter_i::GetPredicate
2290 // Purpose : Get predicate
2291 //=======================================================================
2292 Predicate_ptr Filter_i::GetPredicate()
2294 if ( myPredicate == 0 )
2295 return SMESH::Predicate::_nil();
2298 SMESH::Predicate_var anObj = myPredicate->_this();
2299 return anObj._retn();
2307 #define ATTR_TYPE "type"
2308 #define ATTR_COMPARE "compare"
2309 #define ATTR_THRESHOLD "threshold"
2310 #define ATTR_UNARY "unary"
2311 #define ATTR_BINARY "binary"
2312 #define ATTR_THRESHOLD_STR "threshold_str"
2313 #define ATTR_TOLERANCE "tolerance"
2314 #define ATTR_ELEMENT_TYPE "ElementType"
2316 //=======================================================================
2318 // Purpose : Convert bool to LDOMString
2319 //=======================================================================
2320 static inline LDOMString toString( CORBA::Boolean val )
2322 return val ? "logical not" : "";
2325 //=======================================================================
2327 // Purpose : Convert LDOMString to bool
2328 //=======================================================================
2329 static inline bool toBool( const LDOMString& theStr )
2331 return theStr.equals( "logical not" );
2334 //=======================================================================
2336 // Purpose : Convert double to LDOMString
2337 //=======================================================================
2338 static inline LDOMString toString( CORBA::Double val )
2341 sprintf( a, "%e", val );
2342 return LDOMString( a );
2345 //=======================================================================
2347 // Purpose : Convert LDOMString to double
2348 //=======================================================================
2349 static inline double toDouble( const LDOMString& theStr )
2351 return atof( theStr.GetString() );
2354 //=======================================================================
2356 // Purpose : Convert functor type to LDOMString
2357 //=======================================================================
2358 static inline LDOMString toString( CORBA::Long theType )
2362 case FT_AspectRatio : return "Aspect ratio";
2363 case FT_Warping : return "Warping";
2364 case FT_MinimumAngle : return "Minimum angle";
2365 case FT_Taper : return "Taper";
2366 case FT_Skew : return "Skew";
2367 case FT_Area : return "Area";
2368 case FT_Volume3D : return "Volume3D";
2369 case FT_BelongToGeom : return "Belong to Geom";
2370 case FT_BelongToPlane : return "Belong to Plane";
2371 case FT_BelongToCylinder: return "Belong to Cylinder";
2372 case FT_BelongToGenSurface: return "Belong to Generic Surface";
2373 case FT_LyingOnGeom : return "Lying on Geom";
2374 case FT_BadOrientedVolume: return "Bad Oriented Volume";
2375 case FT_RangeOfIds : return "Range of IDs";
2376 case FT_FreeBorders : return "Free borders";
2377 case FT_FreeEdges : return "Free edges";
2378 case FT_MultiConnection : return "Borders at multi-connections";
2379 case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2380 case FT_Length : return "Length";
2381 case FT_Length2D : return "Length2D";
2382 case FT_LessThan : return "Less than";
2383 case FT_MoreThan : return "More than";
2384 case FT_EqualTo : return "Equal to";
2385 case FT_LogicalNOT : return "Not";
2386 case FT_LogicalAND : return "And";
2387 case FT_LogicalOR : return "Or";
2388 case FT_Undefined : return "";
2389 default : return "";
2393 //=======================================================================
2394 // name : toFunctorType
2395 // Purpose : Convert LDOMString to functor type
2396 //=======================================================================
2397 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
2399 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
2400 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
2401 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
2402 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
2403 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
2404 else if ( theStr.equals( "Area" ) ) return FT_Area;
2405 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
2406 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
2407 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
2408 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
2409 else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface;
2410 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
2411 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
2412 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
2413 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
2414 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
2415 else if ( theStr.equals( "Length" ) ) return FT_Length;
2416 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
2417 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
2418 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
2419 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
2420 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
2421 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
2422 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
2423 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
2424 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
2425 else if ( theStr.equals( "" ) ) return FT_Undefined;
2426 else return FT_Undefined;
2429 //=======================================================================
2430 // name : toFunctorType
2431 // Purpose : Convert LDOMString to value of ElementType enumeration
2432 //=======================================================================
2433 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
2435 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
2436 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
2437 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
2438 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
2439 else return SMESH::ALL;
2442 //=======================================================================
2444 // Purpose : Convert ElementType to string
2445 //=======================================================================
2446 static inline LDOMString toString( const SMESH::ElementType theType )
2450 case SMESH::NODE : return "NODE";
2451 case SMESH::EDGE : return "EDGE";
2452 case SMESH::FACE : return "FACE";
2453 case SMESH::VOLUME : return "VOLUME";
2454 case SMESH::ALL : return "ALL";
2455 default : return "";
2459 //=======================================================================
2460 // name : findFilter
2461 // Purpose : Find filter in document
2462 //=======================================================================
2463 static LDOM_Element findFilter( const char* theFilterName,
2464 const LDOM_Document& theDoc,
2465 LDOM_Node* theParent = 0 )
2467 LDOM_Element aRootElement = theDoc.getDocumentElement();
2468 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
2469 return LDOM_Element();
2471 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
2472 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
2474 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
2475 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2477 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
2478 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
2479 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
2481 if ( theParent != 0 )
2482 *theParent = aTypeNode;
2483 return (LDOM_Element&)aFilter;
2487 return LDOM_Element();
2490 //=======================================================================
2491 // name : getSectionName
2492 // Purpose : Get name of section of filters
2493 //=======================================================================
2494 static const char* getSectionName( const ElementType theType )
2498 case SMESH::NODE : return "Filters for nodes";
2499 case SMESH::EDGE : return "Filters for edges";
2500 case SMESH::FACE : return "Filters for faces";
2501 case SMESH::VOLUME : return "Filters for volumes";
2502 case SMESH::ALL : return "Filters for elements";
2503 default : return "";
2507 //=======================================================================
2508 // name : getSection
2509 // Purpose : Create section for filters corresponding to the entity type
2510 //=======================================================================
2511 static LDOM_Node getSection( const ElementType theType,
2512 LDOM_Document& theDoc,
2513 const bool toCreate = false )
2515 LDOM_Element aRootElement = theDoc.getDocumentElement();
2516 if ( aRootElement.isNull() )
2520 bool anExist = false;
2521 const char* aSectionName = getSectionName( theType );
2522 if ( strcmp( aSectionName, "" ) == 0 )
2525 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
2527 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
2529 aNode = aSections.item( i );
2530 LDOM_Element& anItem = ( LDOM_Element& )aNode;
2531 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
2538 // Create new section if necessary
2543 LDOM_Element aNewItem = theDoc.createElement( "section" );
2544 aNewItem.setAttribute( "name", aSectionName );
2545 aRootElement.appendChild( aNewItem );
2555 //=======================================================================
2556 // name : createFilterItem
2557 // Purpose : Create filter item or LDOM document
2558 //=======================================================================
2559 static LDOM_Element createFilterItem( const char* theName,
2560 SMESH::Filter_ptr theFilter,
2561 LDOM_Document& theDoc )
2563 // create new filter in document
2564 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
2565 aFilterItem.setAttribute( "name", theName );
2567 // save filter criterions
2568 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2570 if ( !theFilter->GetCriteria( aCriteria ) )
2571 return LDOM_Element();
2573 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
2575 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
2577 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
2578 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
2579 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
2580 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
2581 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
2583 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
2584 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
2585 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
2586 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
2588 aFilterItem.appendChild( aCriterionItem );
2594 //=======================================================================
2595 // name : FilterLibrary_i::FilterLibrary_i
2596 // Purpose : Constructor
2597 //=======================================================================
2598 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
2600 myFileName = strdup( theFileName );
2601 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
2602 myFilterMgr = aFilterMgr->_this();
2606 // Try to use existing library file
2607 bool anExists = false;
2608 if ( !aParser.parse( myFileName ) )
2610 myDoc = aParser.getDocument();
2613 // Create a new XML document if it doesn't exist
2615 myDoc = LDOM_Document::createDocument( LDOMString() );
2617 LDOM_Element aRootElement = myDoc.getDocumentElement();
2618 if ( aRootElement.isNull() )
2620 // If the existing document is empty --> try to create a new one
2622 myDoc = LDOM_Document::createDocument( LDOMString() );
2626 //=======================================================================
2627 // name : FilterLibrary_i::FilterLibrary_i
2628 // Purpose : Constructor
2629 //=======================================================================
2630 FilterLibrary_i::FilterLibrary_i()
2633 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2634 myFilterMgr = aFilter->_this();
2636 myDoc = LDOM_Document::createDocument( LDOMString() );
2639 FilterLibrary_i::~FilterLibrary_i()
2642 //TPythonDump()<<this<<".Destroy()";
2645 //=======================================================================
2646 // name : FilterLibrary_i::Copy
2647 // Purpose : Create filter and initialize it with values from library
2648 //=======================================================================
2649 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
2651 Filter_ptr aRes = Filter::_nil();
2652 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
2654 if ( aFilter.isNull() )
2657 std::list<SMESH::Filter::Criterion> aCriteria;
2659 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
2660 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
2662 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
2664 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
2665 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
2666 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
2667 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
2668 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
2670 SMESH::Filter::Criterion aCriterion = createCriterion();
2672 aCriterion.Type = toFunctorType( aTypeStr );
2673 aCriterion.Compare = toFunctorType( aCompareStr );
2674 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
2675 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
2677 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
2679 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
2681 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2682 ? val : atof( str.GetString() );
2684 str = aCrit->getAttribute( ATTR_TOLERANCE );
2685 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2686 ? val : atof( str.GetString() );
2688 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
2689 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
2692 sprintf( a, "%d", val );
2693 aCriterion.ThresholdStr = strdup( a );
2696 aCriterion.ThresholdStr = str.GetString();
2698 aCriteria.push_back( aCriterion );
2701 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
2702 aCriteriaVar->length( aCriteria.size() );
2705 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
2707 for( ; anIter != aCriteria.end(); ++anIter )
2708 aCriteriaVar[ i++ ] = *anIter;
2710 aRes = myFilterMgr->CreateFilter();
2711 aRes->SetCriteria( aCriteriaVar.inout() );
2713 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
2718 //=======================================================================
2719 // name : FilterLibrary_i::SetFileName
2720 // Purpose : Set file name for library
2721 //=======================================================================
2722 void FilterLibrary_i::SetFileName( const char* theFileName )
2725 myFileName = strdup( theFileName );
2726 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
2729 //=======================================================================
2730 // name : FilterLibrary_i::GetFileName
2731 // Purpose : Get file name of library
2732 //=======================================================================
2733 char* FilterLibrary_i::GetFileName()
2735 return CORBA::string_dup( myFileName );
2738 //=======================================================================
2739 // name : FilterLibrary_i::Add
2740 // Purpose : Add new filter to library
2741 //=======================================================================
2742 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
2744 // if filter already in library or entry filter is null do nothing
2745 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2746 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
2749 // get section corresponding to the filter type
2750 ElementType anEntType = theFilter->GetElementType();
2752 LDOM_Node aSection = getSection( anEntType, myDoc, true );
2753 if ( aSection.isNull() )
2756 // create filter item
2757 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
2758 if ( aFilterItem.isNull() )
2762 aSection.appendChild( aFilterItem );
2763 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2764 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
2769 //=======================================================================
2770 // name : FilterLibrary_i::Add
2771 // Purpose : Add new filter to library
2772 //=======================================================================
2773 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
2775 // if filter already in library or entry filter is null do nothing
2776 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2777 if ( !aFilterNode.isNull() )
2780 LDOM_Node aSection = getSection( theType, myDoc, true );
2781 if ( aSection.isNull() )
2784 // create filter item
2785 Filter_var aFilter = myFilterMgr->CreateFilter();
2787 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
2788 if ( aFilterItem.isNull() )
2792 aSection.appendChild( aFilterItem );
2793 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
2798 //=======================================================================
2799 // name : FilterLibrary_i::Delete
2800 // Purpose : Delete filter from library
2801 //=======================================================================
2802 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
2804 LDOM_Node aParentNode;
2805 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
2806 if ( aFilterNode.isNull() || aParentNode.isNull() )
2809 aParentNode.removeChild( aFilterNode );
2810 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
2814 //=======================================================================
2815 // name : FilterLibrary_i::Replace
2816 // Purpose : Replace existing filter with entry filter.
2817 // IMPORTANT : If filter does not exist it is not created
2818 //=======================================================================
2819 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
2820 const char* theNewName,
2821 Filter_ptr theFilter )
2823 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
2824 if ( aFilterItem.isNull() || theFilter->_is_nil() )
2827 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
2828 if ( aNewItem.isNull() )
2832 aFilterItem.ReplaceElement( aNewItem );
2833 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2834 TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
2839 //=======================================================================
2840 // name : FilterLibrary_i::Save
2841 // Purpose : Save library on disk
2842 //=======================================================================
2843 CORBA::Boolean FilterLibrary_i::Save()
2845 if ( myFileName == 0 || strlen( myFileName ) == 0 )
2848 FILE* aOutFile = fopen( myFileName, "wt" );
2852 LDOM_XmlWriter aWriter( aOutFile );
2853 aWriter.SetIndentation( 2 );
2857 TPythonDump()<<this<<".Save()";
2861 //=======================================================================
2862 // name : FilterLibrary_i::SaveAs
2863 // Purpose : Save library on disk
2864 //=======================================================================
2865 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
2867 myFileName = strdup ( aFileName );
2868 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
2872 //=======================================================================
2873 // name : FilterLibrary_i::IsPresent
2874 // Purpose : Verify whether filter is in library
2875 //=======================================================================
2876 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
2878 return !findFilter( theFilterName, myDoc ).isNull();
2881 //=======================================================================
2882 // name : FilterLibrary_i::NbFilters
2883 // Purpose : Return amount of filters in library
2884 //=======================================================================
2885 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
2887 string_array_var aNames = GetNames( theType );
2888 return aNames->length();
2891 //=======================================================================
2892 // name : FilterLibrary_i::GetNames
2893 // Purpose : Get names of filters from library
2894 //=======================================================================
2895 string_array* FilterLibrary_i::GetNames( ElementType theType )
2897 string_array_var anArray = new string_array;
2898 TColStd_SequenceOfHAsciiString aSeq;
2900 LDOM_Node aSection = getSection( theType, myDoc, false );
2902 if ( !aSection.isNull() )
2904 for ( LDOM_Node aFilter = aSection.getFirstChild();
2905 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2907 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
2908 aSeq.Append( new TCollection_HAsciiString(
2909 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
2913 anArray->length( aSeq.Length() );
2914 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
2915 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
2917 return anArray._retn();
2920 //=======================================================================
2921 // name : FilterLibrary_i::GetAllNames
2922 // Purpose : Get names of filters from library
2923 //=======================================================================
2924 string_array* FilterLibrary_i::GetAllNames()
2926 string_array_var aResArray = new string_array;
2927 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
2929 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
2931 int aPrevLength = aResArray->length();
2932 aResArray->length( aPrevLength + aNames->length() );
2933 for ( int i = 0, n = aNames->length(); i < n; i++ )
2934 aResArray[ aPrevLength + i ] = aNames[ i ];
2937 return aResArray._retn();