1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Filter_i.cxx
25 // Author : Alexey Petrov, OCC
29 #include "SMESH_Filter_i.hxx"
31 #include "SMESH_Gen_i.hxx"
32 #include "SMESH_PythonDump.hxx"
34 #include "SMDS_Mesh.hxx"
35 #include "SMDS_MeshNode.hxx"
36 #include "SMDS_MeshElement.hxx"
38 #include "SMESHDS_Mesh.hxx"
40 #include <LDOM_Document.hxx>
41 #include <LDOM_Element.hxx>
42 #include <LDOM_Node.hxx>
43 #include <LDOMString.hxx>
44 #include <LDOMParser.hxx>
45 #include <LDOM_XmlWriter.hxx>
46 #include <TCollection_HAsciiString.hxx>
47 #include <TColStd_ListIteratorOfListOfInteger.hxx>
48 #include <TColStd_ListOfInteger.hxx>
49 #include <TColStd_ListOfReal.hxx>
50 #include <TColStd_MapOfInteger.hxx>
51 #include <TColStd_SequenceOfHAsciiString.hxx>
52 #include <TColStd_ListIteratorOfListOfReal.hxx>
53 #include <Precision.hxx>
54 #include <BRep_Tool.hxx>
55 #include <TopoDS_Shape.hxx>
57 #include <TopoDS_Face.hxx>
58 #include <Geom_Plane.hxx>
59 #include <Geom_CylindricalSurface.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <OSD_Path.hxx>
62 #include <OSD_File.hxx>
64 using namespace SMESH;
65 using namespace SMESH::Controls;
71 GetPredicate( Predicate_ptr thePredicate )
73 return DownCast<Predicate_i*>(thePredicate);
80 Description : Predicate for verifying whether entiy belong to
81 specified geometrical support
84 Controls::BelongToGeom::BelongToGeom()
89 void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
91 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
94 void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
99 static bool IsContains( const SMESHDS_Mesh* theMeshDS,
100 const TopoDS_Shape& theShape,
101 const SMDS_MeshElement* theElem,
102 TopAbs_ShapeEnum theFindShapeEnum,
103 TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE )
105 TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
107 while( anExp.More() )
109 const TopoDS_Shape& aShape = anExp.Current();
110 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
111 if( aSubMesh->Contains( theElem ) )
119 bool Controls::BelongToGeom::IsSatisfy( long theId )
121 if ( myMeshDS == 0 || myShape.IsNull() )
124 if( myType == SMDSAbs_Node )
126 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
128 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
129 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
130 switch( aTypeOfPosition )
132 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
133 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
134 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
135 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
141 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
143 if( myType == SMDSAbs_All )
145 return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
146 IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
147 IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
148 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
150 else if( myType == anElem->GetType() )
154 case SMDSAbs_Edge : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
155 case SMDSAbs_Face : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
156 case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
157 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
166 void Controls::BelongToGeom::SetType( SMDSAbs_ElementType theType )
171 SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
176 TopoDS_Shape Controls::BelongToGeom::GetShape()
182 Controls::BelongToGeom::
190 Description : Predicate for verifying whether entiy lying or partially lying on
191 specified geometrical support
194 Controls::LyingOnGeom::LyingOnGeom()
199 void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
201 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
204 void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
209 bool Controls::LyingOnGeom::IsSatisfy( long theId )
211 if ( myMeshDS == 0 || myShape.IsNull() )
214 if( myType == SMDSAbs_Node )
216 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
218 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
219 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
220 switch( aTypeOfPosition )
222 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
223 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
224 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
225 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
231 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
233 if( myType == SMDSAbs_All )
235 return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
236 Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
237 Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
238 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
240 else if( myType == anElem->GetType() )
244 case SMDSAbs_Edge : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
245 case SMDSAbs_Face : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
246 case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
247 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
256 void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
261 SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
266 TopoDS_Shape Controls::LyingOnGeom::GetShape()
272 Controls::LyingOnGeom::
278 bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh* theMeshDS,
279 const TopoDS_Shape& theShape,
280 const SMDS_MeshElement* theElem,
281 TopAbs_ShapeEnum theFindShapeEnum,
282 TopAbs_ShapeEnum theAvoidShapeEnum )
284 if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
287 TopTools_IndexedMapOfShape aSubShapes;
288 TopExp::MapShapes( theShape, aSubShapes );
290 for (int i = 1; i <= aSubShapes.Extent(); i++)
292 const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
294 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
295 if( aSubMesh->Contains( theElem ) )
298 SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
299 while ( aNodeIt->more() )
301 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
302 SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
303 while ( anElemIt->more() )
305 const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
306 if (anElement == theElem)
322 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
324 SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
325 return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
330 toArray( const TColStd_ListOfInteger& aList )
332 SMESH::long_array_var anArray = new SMESH::long_array;
333 anArray->length( aList.Extent() );
334 TColStd_ListIteratorOfListOfInteger anIter( aList );
336 for( ; anIter.More(); anIter.Next() )
337 anArray[ i++ ] = anIter.Value();
339 return anArray._retn();
344 toArray( const TColStd_ListOfReal& aList )
346 SMESH::double_array_var anArray = new SMESH::double_array;
347 anArray->length( aList.Extent() );
348 TColStd_ListIteratorOfListOfReal anIter( aList );
350 for( ; anIter.More(); anIter.Next() )
351 anArray[ i++ ] = anIter.Value();
353 return anArray._retn();
356 static SMESH::Filter::Criterion createCriterion()
358 SMESH::Filter::Criterion aCriterion;
360 aCriterion.Type = FT_Undefined;
361 aCriterion.Compare = FT_Undefined;
362 aCriterion.Threshold = 0;
363 aCriterion.UnaryOp = FT_Undefined;
364 aCriterion.BinaryOp = FT_Undefined;
365 aCriterion.ThresholdStr = "";
366 aCriterion.ThresholdID = "";
367 aCriterion.Tolerance = Precision::Confusion();
368 aCriterion.TypeOfElement = SMESH::ALL;
369 aCriterion.Precision = -1;
374 static TopoDS_Shape getShapeByName( const char* theName )
378 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
379 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
380 if (!CORBA::is_nil(aStudy))
382 SALOMEDS::Study::ListOfSObject_var aList =
383 aStudy->FindObjectByName( theName, "GEOM" );
384 if ( aList->length() > 0 )
386 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
387 if ( !aGeomObj->_is_nil() )
389 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
390 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
396 return TopoDS_Shape();
399 static TopoDS_Shape getShapeByID( const char* theID )
401 if ( theID != 0 && theID!="" )
403 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
404 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
407 CORBA::Object_var obj = aStudy->ConvertIORToObject(theID);
408 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( obj );
410 if ( !aGeomObj->_is_nil() )
412 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
413 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
418 return TopoDS_Shape();
421 static char* getShapeNameByID ( const char* theID )
425 if ( theID != 0 && theID!="" )
427 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
428 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
431 SALOMEDS::SObject_var aSObj = aStudy->FindObjectIOR( theID );
432 SALOMEDS::GenericAttribute_var anAttr;
433 if ( !aSObj->_is_nil() && aSObj->FindAttribute( anAttr, "AttributeName") )
435 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow( anAttr );
436 aName = aNameAttr->Value();
450 Description : An abstact class for all functors
452 Functor_i::Functor_i():
453 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
455 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
456 //PortableServer::ObjectId_var anObjectId =
457 // SMESH_Gen_i::GetPOA()->activate_object( this );
460 Functor_i::~Functor_i()
462 //TPythonDump()<<this<<".Destroy()";
465 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
467 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
468 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
471 ElementType Functor_i::GetElementType()
473 return ( ElementType )myFunctorPtr->GetType();
478 Class : NumericalFunctor_i
479 Description : Base class for numerical functors
481 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
483 return myNumericalFunctorPtr->GetValue( theId );
486 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
488 myNumericalFunctorPtr->SetPrecision( thePrecision );
489 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
492 CORBA::Long NumericalFunctor_i::GetPrecision()
494 return myNumericalFunctorPtr->GetPrecision();
497 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
499 return myNumericalFunctorPtr;
504 Class : SMESH_MinimumAngle
505 Description : Functor for calculation of minimum angle
507 MinimumAngle_i::MinimumAngle_i()
509 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
510 myFunctorPtr = myNumericalFunctorPtr;
513 FunctorType MinimumAngle_i::GetFunctorType()
515 return SMESH::FT_MinimumAngle;
521 Description : Functor for calculating aspect ratio
523 AspectRatio_i::AspectRatio_i()
525 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
526 myFunctorPtr = myNumericalFunctorPtr;
529 FunctorType AspectRatio_i::GetFunctorType()
531 return SMESH::FT_AspectRatio;
536 Class : AspectRatio3D
537 Description : Functor for calculating aspect ratio 3D
539 AspectRatio3D_i::AspectRatio3D_i()
541 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
542 myFunctorPtr = myNumericalFunctorPtr;
545 FunctorType AspectRatio3D_i::GetFunctorType()
547 return SMESH::FT_AspectRatio3D;
553 Description : Functor for calculating warping
555 Warping_i::Warping_i()
557 myNumericalFunctorPtr.reset( new Controls::Warping() );
558 myFunctorPtr = myNumericalFunctorPtr;
561 FunctorType Warping_i::GetFunctorType()
563 return SMESH::FT_Warping;
569 Description : Functor for calculating taper
573 myNumericalFunctorPtr.reset( new Controls::Taper() );
574 myFunctorPtr = myNumericalFunctorPtr;
577 FunctorType Taper_i::GetFunctorType()
579 return SMESH::FT_Taper;
585 Description : Functor for calculating skew in degrees
589 myNumericalFunctorPtr.reset( new Controls::Skew() );
590 myFunctorPtr = myNumericalFunctorPtr;
593 FunctorType Skew_i::GetFunctorType()
595 return SMESH::FT_Skew;
600 Description : Functor for calculating area
604 myNumericalFunctorPtr.reset( new Controls::Area() );
605 myFunctorPtr = myNumericalFunctorPtr;
608 FunctorType Area_i::GetFunctorType()
610 return SMESH::FT_Area;
615 Description : Functor for calculating volume of 3D element
617 Volume3D_i::Volume3D_i()
619 myNumericalFunctorPtr.reset( new Controls::Volume() );
620 myFunctorPtr = myNumericalFunctorPtr;
623 FunctorType Volume3D_i::GetFunctorType()
625 return SMESH::FT_Volume3D;
630 Description : Functor for calculating length off edge
634 myNumericalFunctorPtr.reset( new Controls::Length() );
635 myFunctorPtr = myNumericalFunctorPtr;
638 FunctorType Length_i::GetFunctorType()
640 return SMESH::FT_Length;
645 Description : Functor for calculating length of edge
647 Length2D_i::Length2D_i()
649 myNumericalFunctorPtr.reset( new Controls::Length2D() );
650 myFunctorPtr = myNumericalFunctorPtr;
653 FunctorType Length2D_i::GetFunctorType()
655 return SMESH::FT_Length2D;
658 SMESH::Length2D::Values* Length2D_i::GetValues()
660 INFOS("Length2D_i::GetValues");
661 SMESH::Controls::Length2D::TValues aValues;
662 myLength2DPtr->GetValues( aValues );
664 long i = 0, iEnd = aValues.size();
666 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
668 SMESH::Controls::Length2D::TValues::const_iterator anIter;
669 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
671 const SMESH::Controls::Length2D::Value& aVal = *anIter;
672 SMESH::Length2D::Value &aValue = aResult[ i ];
674 aValue.myLength = aVal.myLength;
675 aValue.myPnt1 = aVal.myPntId[ 0 ];
676 aValue.myPnt2 = aVal.myPntId[ 1 ];
679 INFOS("Length2D_i::GetValuess~");
680 return aResult._retn();
684 Class : MultiConnection_i
685 Description : Functor for calculating number of faces conneted to the edge
687 MultiConnection_i::MultiConnection_i()
689 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
690 myFunctorPtr = myNumericalFunctorPtr;
693 FunctorType MultiConnection_i::GetFunctorType()
695 return SMESH::FT_MultiConnection;
699 Class : MultiConnection2D_i
700 Description : Functor for calculating number of faces conneted to the edge
702 MultiConnection2D_i::MultiConnection2D_i()
704 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
705 myFunctorPtr = myNumericalFunctorPtr;
708 FunctorType MultiConnection2D_i::GetFunctorType()
710 return SMESH::FT_MultiConnection2D;
713 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
715 INFOS("MultiConnection2D_i::GetValues");
716 SMESH::Controls::MultiConnection2D::MValues aValues;
717 myMulticonnection2DPtr->GetValues( aValues );
719 long i = 0, iEnd = aValues.size();
721 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
723 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
724 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
726 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
727 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
729 aValue.myPnt1 = aVal.myPntId[ 0 ];
730 aValue.myPnt2 = aVal.myPntId[ 1 ];
731 aValue.myNbConnects = (*anIter).second;
734 INFOS("Multiconnection2D_i::GetValuess~");
735 return aResult._retn();
745 Description : Base class for all predicates
747 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
749 return myPredicatePtr->IsSatisfy( theId );
752 Controls::PredicatePtr Predicate_i::GetPredicate()
754 return myPredicatePtr;
758 Class : BadOrientedVolume_i
759 Description : Verify whether a mesh volume is incorrectly oriented from
760 the point of view of MED convention
762 BadOrientedVolume_i::BadOrientedVolume_i()
764 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
765 myFunctorPtr = myPredicatePtr = control;
768 FunctorType BadOrientedVolume_i::GetFunctorType()
770 return SMESH::FT_BadOrientedVolume;
774 Class : BelongToGeom_i
775 Description : Predicate for selection on geometrical support
777 BelongToGeom_i::BelongToGeom_i()
779 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
780 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
785 BelongToGeom_i::~BelongToGeom_i()
791 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
793 if ( theGeom->_is_nil() )
795 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
796 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
797 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
798 myBelongToGeomPtr->SetGeom( aLocShape );
799 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
802 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
804 myBelongToGeomPtr->SetGeom( theShape );
807 void BelongToGeom_i::SetElementType(ElementType theType){
808 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
809 TPythonDump()<<this<<".SetElementType("<<theType<<")";
812 FunctorType BelongToGeom_i::GetFunctorType()
814 return SMESH::FT_BelongToGeom;
817 void BelongToGeom_i::SetShapeName( const char* theName )
820 myShapeName = strdup( theName );
821 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
822 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
825 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
828 myShapeName = strdup( theName );
831 myShapeID = strdup( theID );
835 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
836 myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
838 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
841 char* BelongToGeom_i::GetShapeName()
843 return CORBA::string_dup( myShapeName );
846 char* BelongToGeom_i::GetShapeID()
848 return CORBA::string_dup( myShapeID );
852 Class : BelongToSurface_i
853 Description : Predicate for selection on geometrical support
855 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
857 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
858 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
861 mySurfaceType = theSurfaceType;
864 BelongToSurface_i::~BelongToSurface_i()
870 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
872 if ( theGeom->_is_nil() )
874 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
875 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
876 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
878 if ( aLocShape.ShapeType() == TopAbs_FACE )
880 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
881 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
883 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
888 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
891 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
894 myShapeName = strdup( theName );
895 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
896 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
899 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
902 myShapeName = strdup( theName );
905 myShapeID = strdup( theID );
909 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
910 myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
912 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
915 char* BelongToSurface_i::GetShapeName()
917 return CORBA::string_dup( myShapeName );
920 char* BelongToSurface_i::GetShapeID()
922 return CORBA::string_dup( myShapeID );
925 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
927 myElementsOnSurfacePtr->SetTolerance( theToler );
928 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
931 CORBA::Double BelongToSurface_i::GetTolerance()
933 return myElementsOnSurfacePtr->GetTolerance();
936 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
938 myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
939 TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
942 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
944 return myElementsOnSurfacePtr->GetUseBoundaries();
949 Class : BelongToPlane_i
950 Description : Verify whether mesh element lie in pointed Geom planar object
953 BelongToPlane_i::BelongToPlane_i()
954 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
958 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
960 BelongToSurface_i::SetSurface( theGeom, theType );
961 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
964 FunctorType BelongToPlane_i::GetFunctorType()
966 return FT_BelongToPlane;
970 Class : BelongToCylinder_i
971 Description : Verify whether mesh element lie in pointed Geom planar object
974 BelongToCylinder_i::BelongToCylinder_i()
975 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
979 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
981 BelongToSurface_i::SetSurface( theGeom, theType );
982 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
985 FunctorType BelongToCylinder_i::GetFunctorType()
987 return FT_BelongToCylinder;
991 Class : BelongToGenSurface_i
992 Description : Verify whether mesh element lie in pointed Geom planar object
995 BelongToGenSurface_i::BelongToGenSurface_i()
996 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1000 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1002 if ( theGeom->_is_nil() )
1004 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1005 if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1006 aLocShape.Nullify();
1008 BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1009 TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1012 FunctorType BelongToGenSurface_i::GetFunctorType()
1014 return FT_BelongToGenSurface;
1018 Class : LyingOnGeom_i
1019 Description : Predicate for selection on geometrical support
1021 LyingOnGeom_i::LyingOnGeom_i()
1023 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1024 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1029 LyingOnGeom_i::~LyingOnGeom_i()
1035 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1037 if ( theGeom->_is_nil() )
1039 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1040 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1041 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1042 myLyingOnGeomPtr->SetGeom( aLocShape );
1043 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1046 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1048 myLyingOnGeomPtr->SetGeom( theShape );
1051 void LyingOnGeom_i::SetElementType(ElementType theType){
1052 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1053 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1056 FunctorType LyingOnGeom_i::GetFunctorType()
1058 return SMESH::FT_LyingOnGeom;
1061 void LyingOnGeom_i::SetShapeName( const char* theName )
1064 myShapeName = strdup( theName );
1065 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1066 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1069 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1072 myShapeName = strdup( theName );
1075 myShapeID = strdup( theID );
1079 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1080 myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
1082 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1085 char* LyingOnGeom_i::GetShapeName()
1087 return CORBA::string_dup( myShapeName );
1090 char* LyingOnGeom_i::GetShapeID()
1092 return CORBA::string_dup( myShapeID );
1096 Class : FreeBorders_i
1097 Description : Predicate for free borders
1099 FreeBorders_i::FreeBorders_i()
1101 myPredicatePtr.reset(new Controls::FreeBorders());
1102 myFunctorPtr = myPredicatePtr;
1105 FunctorType FreeBorders_i::GetFunctorType()
1107 return SMESH::FT_FreeBorders;
1112 Description : Predicate for free borders
1114 FreeEdges_i::FreeEdges_i()
1115 : myFreeEdgesPtr( new Controls::FreeEdges() )
1117 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1120 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1122 INFOS("FreeEdges_i::GetBorders");
1123 SMESH::Controls::FreeEdges::TBorders aBorders;
1124 myFreeEdgesPtr->GetBoreders( aBorders );
1126 long i = 0, iEnd = aBorders.size();
1128 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1129 aResult->length(iEnd);
1131 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1132 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1134 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1135 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1137 aBorder.myElemId = aBord.myElemId;
1138 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1139 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1142 INFOS("FreeEdges_i::GetBorders~");
1143 return aResult._retn();
1146 FunctorType FreeEdges_i::GetFunctorType()
1148 return SMESH::FT_FreeEdges;
1152 Class : RangeOfIds_i
1153 Description : Predicate for Range of Ids.
1154 Range may be specified with two ways.
1155 1. Using AddToRange method
1156 2. With SetRangeStr method. Parameter of this method is a string
1157 like as "1,2,3,50-60,63,67,70-"
1160 RangeOfIds_i::RangeOfIds_i()
1162 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1163 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1166 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1168 CORBA::Long iEnd = theIds.length();
1169 for ( CORBA::Long i = 0; i < iEnd; i++ )
1170 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1171 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1174 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1176 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1177 return myRangeOfIdsPtr->SetRangeStr(
1178 TCollection_AsciiString( (Standard_CString)theRange ) );
1181 char* RangeOfIds_i::GetRangeStr()
1183 TCollection_AsciiString aStr;
1184 myRangeOfIdsPtr->GetRangeStr( aStr );
1185 return CORBA::string_dup( aStr.ToCString() );
1188 void RangeOfIds_i::SetElementType( ElementType theType )
1190 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1191 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1194 FunctorType RangeOfIds_i::GetFunctorType()
1196 return SMESH::FT_RangeOfIds;
1200 Class : Comparator_i
1201 Description : Base class for comparators
1203 Comparator_i::Comparator_i():
1204 myNumericalFunctor( NULL )
1207 Comparator_i::~Comparator_i()
1209 if ( myNumericalFunctor )
1210 myNumericalFunctor->Destroy();
1213 void Comparator_i::SetMargin( CORBA::Double theValue )
1215 myComparatorPtr->SetMargin( theValue );
1216 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1219 CORBA::Double Comparator_i::GetMargin()
1221 return myComparatorPtr->GetMargin();
1224 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1226 if ( myNumericalFunctor )
1227 myNumericalFunctor->Destroy();
1229 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1231 if ( myNumericalFunctor )
1233 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1234 myNumericalFunctor->Register();
1235 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1239 Controls::ComparatorPtr Comparator_i::GetComparator()
1241 return myComparatorPtr;
1244 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1246 return myNumericalFunctor;
1252 Description : Comparator "<"
1254 LessThan_i::LessThan_i()
1256 myComparatorPtr.reset( new Controls::LessThan() );
1257 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1260 FunctorType LessThan_i::GetFunctorType()
1262 return SMESH::FT_LessThan;
1268 Description : Comparator ">"
1270 MoreThan_i::MoreThan_i()
1272 myComparatorPtr.reset( new Controls::MoreThan() );
1273 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1276 FunctorType MoreThan_i::GetFunctorType()
1278 return SMESH::FT_MoreThan;
1284 Description : Comparator "="
1286 EqualTo_i::EqualTo_i()
1287 : myEqualToPtr( new Controls::EqualTo() )
1289 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1292 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1294 myEqualToPtr->SetTolerance( theToler );
1295 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1298 CORBA::Double EqualTo_i::GetTolerance()
1300 return myEqualToPtr->GetTolerance();
1303 FunctorType EqualTo_i::GetFunctorType()
1305 return SMESH::FT_EqualTo;
1309 Class : LogicalNOT_i
1310 Description : Logical NOT predicate
1312 LogicalNOT_i::LogicalNOT_i()
1313 : myPredicate( NULL ),
1314 myLogicalNOTPtr( new Controls::LogicalNOT() )
1316 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1319 LogicalNOT_i::~LogicalNOT_i()
1322 myPredicate->Destroy();
1325 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1328 myPredicate->Destroy();
1330 myPredicate = SMESH::GetPredicate(thePredicate);
1333 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1334 myPredicate->Register();
1335 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1339 FunctorType LogicalNOT_i::GetFunctorType()
1341 return SMESH::FT_LogicalNOT;
1344 Predicate_i* LogicalNOT_i::GetPredicate_i()
1351 Class : LogicalBinary_i
1352 Description : Base class for binary logical predicate
1354 LogicalBinary_i::LogicalBinary_i()
1355 : myPredicate1( NULL ),
1356 myPredicate2( NULL )
1359 LogicalBinary_i::~LogicalBinary_i()
1362 myPredicate1->Destroy();
1365 myPredicate2->Destroy();
1368 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1371 myPredicate1->SetMesh( theMesh );
1374 myPredicate2->SetMesh( theMesh );
1377 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1380 myPredicate1->Destroy();
1382 myPredicate1 = SMESH::GetPredicate(thePredicate);
1384 if ( myPredicate1 ){
1385 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1386 myPredicate1->Register();
1387 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1391 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1394 myPredicate2->Destroy();
1396 myPredicate2 = SMESH::GetPredicate(thePredicate);
1398 if ( myPredicate2 ){
1399 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1400 myPredicate2->Register();
1401 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1405 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1407 return myLogicalBinaryPtr;
1410 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1412 return myPredicate1;
1414 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1416 return myPredicate2;
1421 Class : LogicalAND_i
1422 Description : Logical AND
1424 LogicalAND_i::LogicalAND_i()
1426 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1427 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1430 FunctorType LogicalAND_i::GetFunctorType()
1432 return SMESH::FT_LogicalAND;
1438 Description : Logical OR
1440 LogicalOR_i::LogicalOR_i()
1442 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1443 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1446 FunctorType LogicalOR_i::GetFunctorType()
1448 return SMESH::FT_LogicalOR;
1456 FilterManager_i::FilterManager_i()
1457 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1459 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
1460 //PortableServer::ObjectId_var anObjectId =
1461 // SMESH_Gen_i::GetPOA()->activate_object( this );
1465 FilterManager_i::~FilterManager_i()
1467 //TPythonDump()<<this<<".Destroy()";
1471 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1473 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1474 SMESH::MinimumAngle_var anObj = aServant->_this();
1475 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1476 return anObj._retn();
1480 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1482 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1483 SMESH::AspectRatio_var anObj = aServant->_this();
1484 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1485 return anObj._retn();
1489 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1491 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1492 SMESH::AspectRatio3D_var anObj = aServant->_this();
1493 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1494 return anObj._retn();
1498 Warping_ptr FilterManager_i::CreateWarping()
1500 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1501 SMESH::Warping_var anObj = aServant->_this();
1502 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1503 return anObj._retn();
1507 Taper_ptr FilterManager_i::CreateTaper()
1509 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1510 SMESH::Taper_var anObj = aServant->_this();
1511 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1512 return anObj._retn();
1516 Skew_ptr FilterManager_i::CreateSkew()
1518 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1519 SMESH::Skew_var anObj = aServant->_this();
1520 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1521 return anObj._retn();
1525 Area_ptr FilterManager_i::CreateArea()
1527 SMESH::Area_i* aServant = new SMESH::Area_i();
1528 SMESH::Area_var anObj = aServant->_this();
1529 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1530 return anObj._retn();
1534 Volume3D_ptr FilterManager_i::CreateVolume3D()
1536 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
1537 SMESH::Volume3D_var anObj = aServant->_this();
1538 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
1539 return anObj._retn();
1543 Length_ptr FilterManager_i::CreateLength()
1545 SMESH::Length_i* aServant = new SMESH::Length_i();
1546 SMESH::Length_var anObj = aServant->_this();
1547 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1548 return anObj._retn();
1551 Length2D_ptr FilterManager_i::CreateLength2D()
1553 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1554 SMESH::Length2D_var anObj = aServant->_this();
1555 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1556 return anObj._retn();
1559 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1561 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1562 SMESH::MultiConnection_var anObj = aServant->_this();
1563 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1564 return anObj._retn();
1567 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1569 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1570 SMESH::MultiConnection2D_var anObj = aServant->_this();
1571 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
1572 return anObj._retn();
1575 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1577 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1578 SMESH::BelongToGeom_var anObj = aServant->_this();
1579 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
1580 return anObj._retn();
1583 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1585 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1586 SMESH::BelongToPlane_var anObj = aServant->_this();
1587 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
1588 return anObj._retn();
1591 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1593 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1594 SMESH::BelongToCylinder_var anObj = aServant->_this();
1595 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
1596 return anObj._retn();
1599 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
1601 SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
1602 SMESH::BelongToGenSurface_var anObj = aServant->_this();
1603 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
1604 return anObj._retn();
1607 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
1609 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
1610 SMESH::LyingOnGeom_var anObj = aServant->_this();
1611 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
1612 return anObj._retn();
1615 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1617 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1618 SMESH::FreeBorders_var anObj = aServant->_this();
1619 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
1620 return anObj._retn();
1623 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1625 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1626 SMESH::FreeEdges_var anObj = aServant->_this();
1627 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
1628 return anObj._retn();
1631 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1633 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1634 SMESH::RangeOfIds_var anObj = aServant->_this();
1635 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
1636 return anObj._retn();
1639 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
1641 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
1642 SMESH::BadOrientedVolume_var anObj = aServant->_this();
1643 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
1644 return anObj._retn();
1647 LessThan_ptr FilterManager_i::CreateLessThan()
1649 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1650 SMESH::LessThan_var anObj = aServant->_this();
1651 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
1652 return anObj._retn();
1656 MoreThan_ptr FilterManager_i::CreateMoreThan()
1658 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1659 SMESH::MoreThan_var anObj = aServant->_this();
1660 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
1661 return anObj._retn();
1664 EqualTo_ptr FilterManager_i::CreateEqualTo()
1666 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1667 SMESH::EqualTo_var anObj = aServant->_this();
1668 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
1669 return anObj._retn();
1673 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1675 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1676 SMESH::LogicalNOT_var anObj = aServant->_this();
1677 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
1678 return anObj._retn();
1682 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
1684 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
1685 SMESH::LogicalAND_var anObj = aServant->_this();
1686 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
1687 return anObj._retn();
1691 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
1693 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
1694 SMESH::LogicalOR_var anObj = aServant->_this();
1695 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
1696 return anObj._retn();
1699 Filter_ptr FilterManager_i::CreateFilter()
1701 SMESH::Filter_i* aServant = new SMESH::Filter_i();
1702 SMESH::Filter_var anObj = aServant->_this();
1703 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
1704 return anObj._retn();
1707 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
1709 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
1710 SMESH::FilterLibrary_var anObj = aServant->_this();
1711 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary("<<aFileName<<")";
1712 return anObj._retn();
1715 FilterLibrary_ptr FilterManager_i::CreateLibrary()
1717 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
1718 SMESH::FilterLibrary_var anObj = aServant->_this();
1719 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
1720 return anObj._retn();
1723 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
1725 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
1726 return remove( aFileName ) ? false : true;
1729 //=============================================================================
1731 * SMESH_Gen_i::CreateFilterManager
1733 * Create filter manager
1735 //=============================================================================
1737 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
1739 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1740 SMESH::FilterManager_var anObj = aFilter->_this();
1741 return anObj._retn();
1749 //=======================================================================
1750 // name : Filter_i::Filter_i
1751 // Purpose : Constructor
1752 //=======================================================================
1753 Filter_i::Filter_i()
1754 : myPredicate( NULL )
1757 //=======================================================================
1758 // name : Filter_i::~Filter_i
1759 // Purpose : Destructor
1760 //=======================================================================
1761 Filter_i::~Filter_i()
1764 myPredicate->Destroy();
1766 if(!CORBA::is_nil(myMesh))
1769 //TPythonDump()<<this<<".Destroy()";
1772 //=======================================================================
1773 // name : Filter_i::SetPredicate
1774 // Purpose : Set predicate
1775 //=======================================================================
1776 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
1779 myPredicate->Destroy();
1781 myPredicate = SMESH::GetPredicate(thePredicate);
1785 myFilter.SetPredicate( myPredicate->GetPredicate() );
1786 myPredicate->Register();
1787 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1791 //=======================================================================
1792 // name : Filter_i::GetElementType
1793 // Purpose : Get entity type
1794 //=======================================================================
1795 SMESH::ElementType Filter_i::GetElementType()
1797 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
1800 //=======================================================================
1801 // name : Filter_i::SetMesh
1802 // Purpose : Set mesh
1803 //=======================================================================
1806 SetMesh( SMESH_Mesh_ptr theMesh )
1808 if(!CORBA::is_nil(theMesh))
1809 theMesh->Register();
1811 if(!CORBA::is_nil(myMesh))
1815 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
1822 return GetElementsId(myMesh);
1825 //=======================================================================
1826 // name : Filter_i::GetElementsId
1827 // Purpose : Get ids of entities
1828 //=======================================================================
1831 GetElementsId( Predicate_i* thePredicate,
1832 const SMDS_Mesh* theMesh,
1833 Controls::Filter::TIdSequence& theSequence )
1836 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
1841 GetElementsId( Predicate_i* thePredicate,
1842 SMESH_Mesh_ptr theMesh,
1843 Controls::Filter::TIdSequence& theSequence )
1846 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
1847 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
1852 GetElementsId( SMESH_Mesh_ptr theMesh )
1854 SMESH::long_array_var anArray = new SMESH::long_array;
1855 if(!CORBA::is_nil(theMesh) && myPredicate){
1856 Controls::Filter::TIdSequence aSequence;
1857 GetElementsId(myPredicate,theMesh,aSequence);
1858 long i = 0, iEnd = aSequence.size();
1859 anArray->length( iEnd );
1860 for ( ; i < iEnd; i++ )
1861 anArray[ i ] = aSequence[i];
1863 return anArray._retn();
1866 //=======================================================================
1867 // name : getCriteria
1868 // Purpose : Retrieve criterions from predicate
1869 //=======================================================================
1870 static inline bool getCriteria( Predicate_i* thePred,
1871 SMESH::Filter::Criteria_out theCriteria )
1873 int aFType = thePred->GetFunctorType();
1877 case FT_FreeBorders:
1880 CORBA::ULong i = theCriteria->length();
1881 theCriteria->length( i + 1 );
1883 theCriteria[ i ] = createCriterion();
1885 theCriteria[ i ].Type = aFType;
1886 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
1889 case FT_BelongToGeom:
1891 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
1893 CORBA::ULong i = theCriteria->length();
1894 theCriteria->length( i + 1 );
1896 theCriteria[ i ] = createCriterion();
1898 theCriteria[ i ].Type = FT_BelongToGeom;
1899 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1900 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1901 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1905 case FT_BelongToPlane:
1906 case FT_BelongToCylinder:
1907 case FT_BelongToGenSurface:
1909 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
1911 CORBA::ULong i = theCriteria->length();
1912 theCriteria->length( i + 1 );
1914 theCriteria[ i ] = createCriterion();
1916 theCriteria[ i ].Type = aFType;
1917 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1918 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1919 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1920 theCriteria[ i ].Tolerance = aPred->GetTolerance();
1924 case FT_LyingOnGeom:
1926 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
1928 CORBA::ULong i = theCriteria->length();
1929 theCriteria->length( i + 1 );
1931 theCriteria[ i ] = createCriterion();
1933 theCriteria[ i ].Type = FT_LyingOnGeom;
1934 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1935 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1936 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1942 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
1944 CORBA::ULong i = theCriteria->length();
1945 theCriteria->length( i + 1 );
1947 theCriteria[ i ] = createCriterion();
1949 theCriteria[ i ].Type = FT_RangeOfIds;
1950 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
1951 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1955 case FT_BadOrientedVolume:
1957 BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
1959 CORBA::ULong i = theCriteria->length();
1960 theCriteria->length( i + 1 );
1962 theCriteria[ i ] = createCriterion();
1964 theCriteria[ i ].Type = FT_BadOrientedVolume;
1965 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1973 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
1975 CORBA::ULong i = theCriteria->length();
1976 theCriteria->length( i + 1 );
1978 theCriteria[ i ] = createCriterion();
1980 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
1981 theCriteria[ i ].Compare = aFType;
1982 theCriteria[ i ].Threshold = aCompar->GetMargin();
1983 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
1985 if ( aFType == FT_EqualTo )
1987 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
1988 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
1995 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
1996 getCriteria( aPred, theCriteria );
1997 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2004 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2005 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2006 if ( !getCriteria( aPred1, theCriteria ) )
2008 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2009 return getCriteria( aPred2, theCriteria );
2019 //=======================================================================
2020 // name : Filter_i::GetCriteria
2021 // Purpose : Retrieve criterions from predicate
2022 //=======================================================================
2023 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2025 theCriteria = new SMESH::Filter::Criteria;
2026 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2029 //=======================================================================
2030 // name : Filter_i::SetCriteria
2031 // Purpose : Create new predicate and set criterions in it
2032 //=======================================================================
2033 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2035 if ( myPredicate != 0 )
2036 myPredicate->Destroy();
2038 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2039 FilterManager_ptr aFilterMgr = aFilter->_this();
2041 // CREATE two lists ( PREDICATES and LOG OP )
2044 TPythonDump()<<"aCriteria = []";
2045 std::list<SMESH::Predicate_ptr> aPredicates;
2046 std::list<int> aBinaries;
2047 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2049 int aCriterion = theCriteria[ i ].Type;
2050 int aCompare = theCriteria[ i ].Compare;
2051 double aThreshold = theCriteria[ i ].Threshold;
2052 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2053 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2054 int aUnary = theCriteria[ i ].UnaryOp;
2055 int aBinary = theCriteria[ i ].BinaryOp;
2056 double aTolerance = theCriteria[ i ].Tolerance;
2057 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
2058 long aPrecision = theCriteria[ i ].Precision;
2060 TPythonDump()<<"aCriterion = SMESH.Filter.Criterion("<<
2061 aCriterion<<","<<aCompare<<","<<aThreshold<<",'"<<aThresholdStr<<"','"<<aThresholdID<<"',"<<
2062 aUnary<<","<<aBinary<<","<<aTolerance<<","<<aTypeOfElem<<","<<aPrecision<<"))";
2064 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2065 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2067 switch ( aCriterion )
2071 case SMESH::FT_MultiConnection:
2072 aFunctor = aFilterMgr->CreateMultiConnection();
2074 case SMESH::FT_MultiConnection2D:
2075 aFunctor = aFilterMgr->CreateMultiConnection2D();
2077 case SMESH::FT_Length:
2078 aFunctor = aFilterMgr->CreateLength();
2080 case SMESH::FT_Length2D:
2081 aFunctor = aFilterMgr->CreateLength2D();
2083 case SMESH::FT_AspectRatio:
2084 aFunctor = aFilterMgr->CreateAspectRatio();
2086 case SMESH::FT_AspectRatio3D:
2087 aFunctor = aFilterMgr->CreateAspectRatio3D();
2089 case SMESH::FT_Warping:
2090 aFunctor = aFilterMgr->CreateWarping();
2092 case SMESH::FT_MinimumAngle:
2093 aFunctor = aFilterMgr->CreateMinimumAngle();
2095 case SMESH::FT_Taper:
2096 aFunctor = aFilterMgr->CreateTaper();
2098 case SMESH::FT_Skew:
2099 aFunctor = aFilterMgr->CreateSkew();
2101 case SMESH::FT_Area:
2102 aFunctor = aFilterMgr->CreateArea();
2104 case SMESH::FT_Volume3D:
2105 aFunctor = aFilterMgr->CreateVolume3D();
2110 case SMESH::FT_FreeBorders:
2111 aPredicate = aFilterMgr->CreateFreeBorders();
2113 case SMESH::FT_FreeEdges:
2114 aPredicate = aFilterMgr->CreateFreeEdges();
2116 case SMESH::FT_BelongToGeom:
2118 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2119 tmpPred->SetElementType( aTypeOfElem );
2120 tmpPred->SetShape( aThresholdID, aThresholdStr );
2121 aPredicate = tmpPred;
2124 case SMESH::FT_BelongToPlane:
2125 case SMESH::FT_BelongToCylinder:
2126 case SMESH::FT_BelongToGenSurface:
2128 SMESH::BelongToSurface_ptr tmpPred;
2129 switch ( aCriterion ) {
2130 case SMESH::FT_BelongToPlane:
2131 tmpPred = aFilterMgr->CreateBelongToPlane(); break;
2132 case SMESH::FT_BelongToCylinder:
2133 tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
2135 tmpPred = aFilterMgr->CreateBelongToGenSurface();
2137 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2138 tmpPred->SetTolerance( aTolerance );
2139 aPredicate = tmpPred;
2142 case SMESH::FT_LyingOnGeom:
2144 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2145 tmpPred->SetElementType( aTypeOfElem );
2146 tmpPred->SetShape( aThresholdID, aThresholdStr );
2147 aPredicate = tmpPred;
2150 case SMESH::FT_RangeOfIds:
2152 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2153 tmpPred->SetRangeStr( aThresholdStr );
2154 tmpPred->SetElementType( aTypeOfElem );
2155 aPredicate = tmpPred;
2158 case SMESH::FT_BadOrientedVolume:
2160 aPredicate = aFilterMgr->CreateBadOrientedVolume();
2169 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
2171 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
2173 if ( aCompare == SMESH::FT_LessThan )
2174 aComparator = aFilterMgr->CreateLessThan();
2175 else if ( aCompare == SMESH::FT_MoreThan )
2176 aComparator = aFilterMgr->CreateMoreThan();
2177 else if ( aCompare == SMESH::FT_EqualTo )
2178 aComparator = aFilterMgr->CreateEqualTo();
2182 aComparator->SetNumFunctor( aFunctor );
2183 aComparator->SetMargin( aThreshold );
2185 if ( aCompare == FT_EqualTo )
2187 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
2188 anEqualTo->SetTolerance( aTolerance );
2191 aPredicate = aComparator;
2193 aFunctor->SetPrecision( aPrecision );
2197 if ( aUnary == FT_LogicalNOT )
2199 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
2200 aNotPred->SetPredicate( aPredicate );
2201 aPredicate = aNotPred;
2205 aPredicates.push_back( aPredicate );
2206 aBinaries.push_back( aBinary );
2207 TPythonDump()<<"aCriteria.append(aCriterion)";
2210 TPythonDump()<<this<<".SetCriteria(aCriteria)";
2212 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
2214 // combine all "AND" operations
2216 std::list<SMESH::Predicate_ptr> aResList;
2218 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
2219 std::list<int>::iterator aBinaryIter;
2221 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
2222 int aPrevBinary = SMESH::FT_Undefined;
2224 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
2225 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
2226 ++aPredIter, ++aBinaryIter )
2228 int aCurrBinary = *aBinaryIter;
2230 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
2232 if ( aPrevBinary == SMESH::FT_LogicalAND )
2235 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2236 aBinaryPred->SetPredicate1( aPrevPredicate );
2237 aBinaryPred->SetPredicate2( *aPredIter );
2238 aCurrPred = aBinaryPred;
2241 aCurrPred = *aPredIter;
2243 if ( aCurrBinary != SMESH::FT_LogicalAND )
2244 aResList.push_back( aCurrPred );
2246 aPrevPredicate = aCurrPred;
2247 aPrevBinary = aCurrBinary;
2250 // combine all "OR" operations
2252 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2254 if ( aResList.size() == 1 )
2255 aResPredicate = *aResList.begin();
2256 else if ( aResList.size() > 1 )
2258 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2259 aResPredicate = *anIter;
2261 for ( ; anIter != aResList.end(); ++anIter )
2263 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2264 aBinaryPred->SetPredicate1( aResPredicate );
2265 aBinaryPred->SetPredicate2( *anIter );
2266 aResPredicate = aBinaryPred;
2270 SetPredicate( aResPredicate );
2272 return !aResPredicate->_is_nil();
2275 //=======================================================================
2276 // name : Filter_i::GetPredicate_i
2277 // Purpose : Get implementation of predicate
2278 //=======================================================================
2279 Predicate_i* Filter_i::GetPredicate_i()
2284 //=======================================================================
2285 // name : Filter_i::GetPredicate
2286 // Purpose : Get predicate
2287 //=======================================================================
2288 Predicate_ptr Filter_i::GetPredicate()
2290 if ( myPredicate == 0 )
2291 return SMESH::Predicate::_nil();
2294 SMESH::Predicate_var anObj = myPredicate->_this();
2295 return anObj._retn();
2303 #define ATTR_TYPE "type"
2304 #define ATTR_COMPARE "compare"
2305 #define ATTR_THRESHOLD "threshold"
2306 #define ATTR_UNARY "unary"
2307 #define ATTR_BINARY "binary"
2308 #define ATTR_THRESHOLD_STR "threshold_str"
2309 #define ATTR_TOLERANCE "tolerance"
2310 #define ATTR_ELEMENT_TYPE "ElementType"
2312 //=======================================================================
2314 // Purpose : Convert bool to LDOMString
2315 //=======================================================================
2316 static inline LDOMString toString( CORBA::Boolean val )
2318 return val ? "logical not" : "";
2321 //=======================================================================
2323 // Purpose : Convert LDOMString to bool
2324 //=======================================================================
2325 static inline bool toBool( const LDOMString& theStr )
2327 return theStr.equals( "logical not" );
2330 //=======================================================================
2332 // Purpose : Convert double to LDOMString
2333 //=======================================================================
2334 static inline LDOMString toString( CORBA::Double val )
2337 sprintf( a, "%e", val );
2338 return LDOMString( a );
2341 //=======================================================================
2343 // Purpose : Convert LDOMString to double
2344 //=======================================================================
2345 static inline double toDouble( const LDOMString& theStr )
2347 return atof( theStr.GetString() );
2350 //=======================================================================
2352 // Purpose : Convert functor type to LDOMString
2353 //=======================================================================
2354 static inline LDOMString toString( CORBA::Long theType )
2358 case FT_AspectRatio : return "Aspect ratio";
2359 case FT_Warping : return "Warping";
2360 case FT_MinimumAngle : return "Minimum angle";
2361 case FT_Taper : return "Taper";
2362 case FT_Skew : return "Skew";
2363 case FT_Area : return "Area";
2364 case FT_Volume3D : return "Volume3D";
2365 case FT_BelongToGeom : return "Belong to Geom";
2366 case FT_BelongToPlane : return "Belong to Plane";
2367 case FT_BelongToCylinder: return "Belong to Cylinder";
2368 case FT_BelongToGenSurface: return "Belong to Generic Surface";
2369 case FT_LyingOnGeom : return "Lying on Geom";
2370 case FT_BadOrientedVolume: return "Bad Oriented Volume";
2371 case FT_RangeOfIds : return "Range of IDs";
2372 case FT_FreeBorders : return "Free borders";
2373 case FT_FreeEdges : return "Free edges";
2374 case FT_MultiConnection : return "Borders at multi-connections";
2375 case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2376 case FT_Length : return "Length";
2377 case FT_Length2D : return "Length2D";
2378 case FT_LessThan : return "Less than";
2379 case FT_MoreThan : return "More than";
2380 case FT_EqualTo : return "Equal to";
2381 case FT_LogicalNOT : return "Not";
2382 case FT_LogicalAND : return "And";
2383 case FT_LogicalOR : return "Or";
2384 case FT_Undefined : return "";
2385 default : return "";
2389 //=======================================================================
2390 // name : toFunctorType
2391 // Purpose : Convert LDOMString to functor type
2392 //=======================================================================
2393 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
2395 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
2396 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
2397 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
2398 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
2399 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
2400 else if ( theStr.equals( "Area" ) ) return FT_Area;
2401 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
2402 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
2403 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
2404 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
2405 else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface;
2406 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
2407 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
2408 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
2409 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
2410 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
2411 else if ( theStr.equals( "Length" ) ) return FT_Length;
2412 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
2413 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
2414 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
2415 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
2416 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
2417 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
2418 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
2419 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
2420 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
2421 else if ( theStr.equals( "" ) ) return FT_Undefined;
2422 else return FT_Undefined;
2425 //=======================================================================
2426 // name : toFunctorType
2427 // Purpose : Convert LDOMString to value of ElementType enumeration
2428 //=======================================================================
2429 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
2431 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
2432 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
2433 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
2434 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
2435 else return SMESH::ALL;
2438 //=======================================================================
2440 // Purpose : Convert ElementType to string
2441 //=======================================================================
2442 static inline LDOMString toString( const SMESH::ElementType theType )
2446 case SMESH::NODE : return "NODE";
2447 case SMESH::EDGE : return "EDGE";
2448 case SMESH::FACE : return "FACE";
2449 case SMESH::VOLUME : return "VOLUME";
2450 case SMESH::ALL : return "ALL";
2451 default : return "";
2455 //=======================================================================
2456 // name : findFilter
2457 // Purpose : Find filter in document
2458 //=======================================================================
2459 static LDOM_Element findFilter( const char* theFilterName,
2460 const LDOM_Document& theDoc,
2461 LDOM_Node* theParent = 0 )
2463 LDOM_Element aRootElement = theDoc.getDocumentElement();
2464 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
2465 return LDOM_Element();
2467 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
2468 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
2470 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
2471 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2473 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
2474 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
2475 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
2477 if ( theParent != 0 )
2478 *theParent = aTypeNode;
2479 return (LDOM_Element&)aFilter;
2483 return LDOM_Element();
2486 //=======================================================================
2487 // name : getSectionName
2488 // Purpose : Get name of section of filters
2489 //=======================================================================
2490 static const char* getSectionName( const ElementType theType )
2494 case SMESH::NODE : return "Filters for nodes";
2495 case SMESH::EDGE : return "Filters for edges";
2496 case SMESH::FACE : return "Filters for faces";
2497 case SMESH::VOLUME : return "Filters for volumes";
2498 case SMESH::ALL : return "Filters for elements";
2499 default : return "";
2503 //=======================================================================
2504 // name : getSection
2505 // Purpose : Create section for filters corresponding to the entity type
2506 //=======================================================================
2507 static LDOM_Node getSection( const ElementType theType,
2508 LDOM_Document& theDoc,
2509 const bool toCreate = false )
2511 LDOM_Element aRootElement = theDoc.getDocumentElement();
2512 if ( aRootElement.isNull() )
2516 bool anExist = false;
2517 const char* aSectionName = getSectionName( theType );
2518 if ( strcmp( aSectionName, "" ) == 0 )
2521 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
2523 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
2525 aNode = aSections.item( i );
2526 LDOM_Element& anItem = ( LDOM_Element& )aNode;
2527 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
2534 // Create new section if necessary
2539 LDOM_Element aNewItem = theDoc.createElement( "section" );
2540 aNewItem.setAttribute( "name", aSectionName );
2541 aRootElement.appendChild( aNewItem );
2551 //=======================================================================
2552 // name : createFilterItem
2553 // Purpose : Create filter item or LDOM document
2554 //=======================================================================
2555 static LDOM_Element createFilterItem( const char* theName,
2556 SMESH::Filter_ptr theFilter,
2557 LDOM_Document& theDoc )
2559 // create new filter in document
2560 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
2561 aFilterItem.setAttribute( "name", theName );
2563 // save filter criterions
2564 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2566 if ( !theFilter->GetCriteria( aCriteria ) )
2567 return LDOM_Element();
2569 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
2571 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
2573 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
2574 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
2575 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
2576 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
2577 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
2579 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
2580 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
2581 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
2582 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
2584 aFilterItem.appendChild( aCriterionItem );
2590 //=======================================================================
2591 // name : FilterLibrary_i::FilterLibrary_i
2592 // Purpose : Constructor
2593 //=======================================================================
2594 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
2596 myFileName = strdup( theFileName );
2597 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
2598 myFilterMgr = aFilterMgr->_this();
2602 // Try to use existing library file
2603 bool anExists = false;
2604 if ( !aParser.parse( myFileName ) )
2606 myDoc = aParser.getDocument();
2609 // Create a new XML document if it doesn't exist
2611 myDoc = LDOM_Document::createDocument( LDOMString() );
2613 LDOM_Element aRootElement = myDoc.getDocumentElement();
2614 if ( aRootElement.isNull() )
2616 // If the existing document is empty --> try to create a new one
2618 myDoc = LDOM_Document::createDocument( LDOMString() );
2622 //=======================================================================
2623 // name : FilterLibrary_i::FilterLibrary_i
2624 // Purpose : Constructor
2625 //=======================================================================
2626 FilterLibrary_i::FilterLibrary_i()
2629 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2630 myFilterMgr = aFilter->_this();
2632 myDoc = LDOM_Document::createDocument( LDOMString() );
2635 FilterLibrary_i::~FilterLibrary_i()
2638 //TPythonDump()<<this<<".Destroy()";
2641 //=======================================================================
2642 // name : FilterLibrary_i::Copy
2643 // Purpose : Create filter and initialize it with values from library
2644 //=======================================================================
2645 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
2647 Filter_ptr aRes = Filter::_nil();
2648 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
2650 if ( aFilter.isNull() )
2653 std::list<SMESH::Filter::Criterion> aCriteria;
2655 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
2656 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
2658 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
2660 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
2661 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
2662 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
2663 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
2664 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
2666 SMESH::Filter::Criterion aCriterion = createCriterion();
2668 aCriterion.Type = toFunctorType( aTypeStr );
2669 aCriterion.Compare = toFunctorType( aCompareStr );
2670 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
2671 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
2673 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
2675 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
2677 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2678 ? val : atof( str.GetString() );
2680 str = aCrit->getAttribute( ATTR_TOLERANCE );
2681 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2682 ? val : atof( str.GetString() );
2684 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
2685 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
2688 sprintf( a, "%d", val );
2689 aCriterion.ThresholdStr = strdup( a );
2692 aCriterion.ThresholdStr = str.GetString();
2694 aCriteria.push_back( aCriterion );
2697 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
2698 aCriteriaVar->length( aCriteria.size() );
2701 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
2703 for( ; anIter != aCriteria.end(); ++anIter )
2704 aCriteriaVar[ i++ ] = *anIter;
2706 aRes = myFilterMgr->CreateFilter();
2707 aRes->SetCriteria( aCriteriaVar.inout() );
2709 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
2714 //=======================================================================
2715 // name : FilterLibrary_i::SetFileName
2716 // Purpose : Set file name for library
2717 //=======================================================================
2718 void FilterLibrary_i::SetFileName( const char* theFileName )
2721 myFileName = strdup( theFileName );
2722 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
2725 //=======================================================================
2726 // name : FilterLibrary_i::GetFileName
2727 // Purpose : Get file name of library
2728 //=======================================================================
2729 char* FilterLibrary_i::GetFileName()
2731 return CORBA::string_dup( myFileName );
2734 //=======================================================================
2735 // name : FilterLibrary_i::Add
2736 // Purpose : Add new filter to library
2737 //=======================================================================
2738 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
2740 // if filter already in library or entry filter is null do nothing
2741 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2742 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
2745 // get section corresponding to the filter type
2746 ElementType anEntType = theFilter->GetElementType();
2748 LDOM_Node aSection = getSection( anEntType, myDoc, true );
2749 if ( aSection.isNull() )
2752 // create filter item
2753 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
2754 if ( aFilterItem.isNull() )
2758 aSection.appendChild( aFilterItem );
2759 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2760 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
2765 //=======================================================================
2766 // name : FilterLibrary_i::Add
2767 // Purpose : Add new filter to library
2768 //=======================================================================
2769 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
2771 // if filter already in library or entry filter is null do nothing
2772 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2773 if ( !aFilterNode.isNull() )
2776 LDOM_Node aSection = getSection( theType, myDoc, true );
2777 if ( aSection.isNull() )
2780 // create filter item
2781 Filter_var aFilter = myFilterMgr->CreateFilter();
2783 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
2784 if ( aFilterItem.isNull() )
2788 aSection.appendChild( aFilterItem );
2789 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
2794 //=======================================================================
2795 // name : FilterLibrary_i::Delete
2796 // Purpose : Delete filter from library
2797 //=======================================================================
2798 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
2800 LDOM_Node aParentNode;
2801 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
2802 if ( aFilterNode.isNull() || aParentNode.isNull() )
2805 aParentNode.removeChild( aFilterNode );
2806 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
2810 //=======================================================================
2811 // name : FilterLibrary_i::Replace
2812 // Purpose : Replace existing filter with entry filter.
2813 // IMPORTANT : If filter does not exist it is not created
2814 //=======================================================================
2815 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
2816 const char* theNewName,
2817 Filter_ptr theFilter )
2819 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
2820 if ( aFilterItem.isNull() || theFilter->_is_nil() )
2823 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
2824 if ( aNewItem.isNull() )
2828 aFilterItem.ReplaceElement( aNewItem );
2829 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2830 TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
2835 //=======================================================================
2836 // name : FilterLibrary_i::Save
2837 // Purpose : Save library on disk
2838 //=======================================================================
2839 CORBA::Boolean FilterLibrary_i::Save()
2841 if ( myFileName == 0 || strlen( myFileName ) == 0 )
2844 FILE* aOutFile = fopen( myFileName, "wt" );
2848 LDOM_XmlWriter aWriter( aOutFile );
2849 aWriter.SetIndentation( 2 );
2853 TPythonDump()<<this<<".Save()";
2857 //=======================================================================
2858 // name : FilterLibrary_i::SaveAs
2859 // Purpose : Save library on disk
2860 //=======================================================================
2861 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
2863 myFileName = strdup ( aFileName );
2864 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
2868 //=======================================================================
2869 // name : FilterLibrary_i::IsPresent
2870 // Purpose : Verify whether filter is in library
2871 //=======================================================================
2872 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
2874 return !findFilter( theFilterName, myDoc ).isNull();
2877 //=======================================================================
2878 // name : FilterLibrary_i::NbFilters
2879 // Purpose : Return amount of filters in library
2880 //=======================================================================
2881 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
2883 string_array_var aNames = GetNames( theType );
2884 return aNames->length();
2887 //=======================================================================
2888 // name : FilterLibrary_i::GetNames
2889 // Purpose : Get names of filters from library
2890 //=======================================================================
2891 string_array* FilterLibrary_i::GetNames( ElementType theType )
2893 string_array_var anArray = new string_array;
2894 TColStd_SequenceOfHAsciiString aSeq;
2896 LDOM_Node aSection = getSection( theType, myDoc, false );
2898 if ( !aSection.isNull() )
2900 for ( LDOM_Node aFilter = aSection.getFirstChild();
2901 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2903 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
2904 aSeq.Append( new TCollection_HAsciiString(
2905 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
2909 anArray->length( aSeq.Length() );
2910 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
2911 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
2913 return anArray._retn();
2916 //=======================================================================
2917 // name : FilterLibrary_i::GetAllNames
2918 // Purpose : Get names of filters from library
2919 //=======================================================================
2920 string_array* FilterLibrary_i::GetAllNames()
2922 string_array_var aResArray = new string_array;
2923 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
2925 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
2927 int aPrevLength = aResArray->length();
2928 aResArray->length( aPrevLength + aNames->length() );
2929 for ( int i = 0, n = aNames->length(); i < n; i++ )
2930 aResArray[ aPrevLength + i ] = aNames[ i ];
2933 return aResArray._retn();