1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 // File : SMESH_Filter_i.cxx
25 // Author : Alexey Petrov, OCC
28 #include "SMESH_Filter_i.hxx"
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_PythonDump.hxx"
33 #include "SMDS_Mesh.hxx"
34 #include "SMDS_MeshNode.hxx"
35 #include "SMDS_MeshElement.hxx"
36 #include "SMDS_ElemIterator.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>
61 #include <TopTools_IndexedMapOfShape.hxx>
63 using namespace SMESH;
64 using namespace SMESH::Controls;
70 GetPredicate( Predicate_ptr thePredicate )
72 return DownCast<Predicate_i*>(thePredicate);
79 Description : Predicate for verifying whether entity belongs to
80 specified geometrical support
83 Controls::BelongToGeom::BelongToGeom()
87 myTolerance(Precision::Confusion())
90 void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
92 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
96 void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
102 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
103 const TopoDS_Shape& theShape)
105 if (theMap.Contains(theShape)) return true;
107 if (theShape.ShapeType() == TopAbs_COMPOUND ||
108 theShape.ShapeType() == TopAbs_COMPSOLID)
110 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
111 for (; anIt.More(); anIt.Next())
113 if (!IsSubShape(theMap, anIt.Value())) {
123 void Controls::BelongToGeom::init()
125 if (!myMeshDS || myShape.IsNull()) return;
127 // is subshape of main shape?
128 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
129 if (aMainShape.IsNull()) {
130 myIsSubshape = false;
133 TopTools_IndexedMapOfShape aMap;
134 TopExp::MapShapes(aMainShape, aMap);
135 myIsSubshape = IsSubShape(aMap, myShape);
140 myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
141 myElementsOnShapePtr->SetTolerance(myTolerance);
142 myElementsOnShapePtr->SetAllNodes(true); // belong, while false means "lays on"
143 myElementsOnShapePtr->SetMesh(myMeshDS);
144 myElementsOnShapePtr->SetShape(myShape, myType);
148 static bool IsContains( const SMESHDS_Mesh* theMeshDS,
149 const TopoDS_Shape& theShape,
150 const SMDS_MeshElement* theElem,
151 TopAbs_ShapeEnum theFindShapeEnum,
152 TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE )
154 TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
156 while( anExp.More() )
158 const TopoDS_Shape& aShape = anExp.Current();
159 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
160 if( aSubMesh->Contains( theElem ) )
168 bool Controls::BelongToGeom::IsSatisfy (long theId)
170 if (myMeshDS == 0 || myShape.IsNull())
175 return myElementsOnShapePtr->IsSatisfy(theId);
179 if (myType == SMDSAbs_Node)
181 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
183 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
184 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
185 switch( aTypeOfPosition )
187 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
188 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
189 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
190 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
196 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
198 if( myType == SMDSAbs_All )
200 return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
201 IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
202 IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
203 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
205 else if( myType == anElem->GetType() )
209 case SMDSAbs_Edge : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
210 case SMDSAbs_Face : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
211 case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
212 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
221 void Controls::BelongToGeom::SetType (SMDSAbs_ElementType theType)
227 SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
232 TopoDS_Shape Controls::BelongToGeom::GetShape()
237 const SMESHDS_Mesh* Controls::BelongToGeom::GetMeshDS() const
242 void Controls::BelongToGeom::SetTolerance (double theTolerance)
244 myTolerance = theTolerance;
249 double Controls::BelongToGeom::GetTolerance()
256 Description : Predicate for verifying whether entiy lying or partially lying on
257 specified geometrical support
260 Controls::LyingOnGeom::LyingOnGeom()
264 myTolerance(Precision::Confusion())
267 void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
269 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
273 void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
279 void Controls::LyingOnGeom::init()
281 if (!myMeshDS || myShape.IsNull()) return;
283 // is subshape of main shape?
284 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
285 if (aMainShape.IsNull()) {
286 myIsSubshape = false;
289 TopTools_IndexedMapOfShape aMap;
290 TopExp::MapShapes(aMainShape, aMap);
291 myIsSubshape = IsSubShape(aMap, myShape);
296 myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
297 myElementsOnShapePtr->SetTolerance(myTolerance);
298 myElementsOnShapePtr->SetAllNodes(false); // lays on, while true means "belong"
299 myElementsOnShapePtr->SetMesh(myMeshDS);
300 myElementsOnShapePtr->SetShape(myShape, myType);
304 bool Controls::LyingOnGeom::IsSatisfy( long theId )
306 if ( myMeshDS == 0 || myShape.IsNull() )
311 return myElementsOnShapePtr->IsSatisfy(theId);
315 if( myType == SMDSAbs_Node )
317 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
319 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
320 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
321 switch( aTypeOfPosition )
323 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
324 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
325 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
326 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
332 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
334 if( myType == SMDSAbs_All )
336 return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
337 Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
338 Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
339 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
341 else if( myType == anElem->GetType() )
345 case SMDSAbs_Edge : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
346 case SMDSAbs_Face : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
347 case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
348 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
357 void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
363 SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
368 TopoDS_Shape Controls::LyingOnGeom::GetShape()
373 const SMESHDS_Mesh* Controls::LyingOnGeom::GetMeshDS() const
378 void Controls::LyingOnGeom::SetTolerance (double theTolerance)
380 myTolerance = theTolerance;
385 double Controls::LyingOnGeom::GetTolerance()
390 bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh* theMeshDS,
391 const TopoDS_Shape& theShape,
392 const SMDS_MeshElement* theElem,
393 TopAbs_ShapeEnum theFindShapeEnum,
394 TopAbs_ShapeEnum theAvoidShapeEnum )
396 if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
399 TopTools_IndexedMapOfShape aSubShapes;
400 TopExp::MapShapes( theShape, aSubShapes );
402 for (int i = 1; i <= aSubShapes.Extent(); i++)
404 const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
406 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
407 if( aSubMesh->Contains( theElem ) )
410 SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
411 while ( aNodeIt->more() )
413 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
414 SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
415 while ( anElemIt->more() )
417 const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
418 if (anElement == theElem)
434 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
436 SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
437 return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
442 toArray( const TColStd_ListOfInteger& aList )
444 SMESH::long_array_var anArray = new SMESH::long_array;
445 anArray->length( aList.Extent() );
446 TColStd_ListIteratorOfListOfInteger anIter( aList );
448 for( ; anIter.More(); anIter.Next() )
449 anArray[ i++ ] = anIter.Value();
451 return anArray._retn();
456 toArray( const TColStd_ListOfReal& aList )
458 SMESH::double_array_var anArray = new SMESH::double_array;
459 anArray->length( aList.Extent() );
460 TColStd_ListIteratorOfListOfReal anIter( aList );
462 for( ; anIter.More(); anIter.Next() )
463 anArray[ i++ ] = anIter.Value();
465 return anArray._retn();
468 static SMESH::Filter::Criterion createCriterion()
470 SMESH::Filter::Criterion aCriterion;
472 aCriterion.Type = FT_Undefined;
473 aCriterion.Compare = FT_Undefined;
474 aCriterion.Threshold = 0;
475 aCriterion.UnaryOp = FT_Undefined;
476 aCriterion.BinaryOp = FT_Undefined;
477 aCriterion.ThresholdStr = "";
478 aCriterion.ThresholdID = "";
479 aCriterion.Tolerance = Precision::Confusion();
480 aCriterion.TypeOfElement = SMESH::ALL;
481 aCriterion.Precision = -1;
486 static TopoDS_Shape getShapeByName( const char* theName )
490 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
491 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
492 if (!CORBA::is_nil(aStudy))
494 SALOMEDS::Study::ListOfSObject_var aList =
495 aStudy->FindObjectByName( theName, "GEOM" );
496 if ( aList->length() > 0 )
498 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
499 if ( !aGeomObj->_is_nil() )
501 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
502 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
508 return TopoDS_Shape();
511 static TopoDS_Shape getShapeByID (const char* theID)
513 if (theID != 0 && theID != "") {
514 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
515 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
517 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
518 SALOMEDS::GenericAttribute_var anAttr;
519 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
520 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
521 CORBA::String_var aVal = anIOR->Value();
522 CORBA::Object_var obj = aStudy->ConvertIORToObject(aVal);
523 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
525 if (!aGeomObj->_is_nil()) {
526 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
527 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
533 return TopoDS_Shape();
536 static char* getShapeNameByID (const char* theID)
538 char* aName = (char*)"";
540 if (theID != 0 && theID != "") {
541 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
542 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
544 //SALOMEDS::SObject_var aSObj = aStudy->FindObjectIOR( theID );
545 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
546 SALOMEDS::GenericAttribute_var anAttr;
547 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeName")) {
548 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
549 aName = aNameAttr->Value();
563 Description : An abstact class for all functors
565 Functor_i::Functor_i():
566 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
568 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
569 //PortableServer::ObjectId_var anObjectId =
570 // SMESH_Gen_i::GetPOA()->activate_object( this );
573 Functor_i::~Functor_i()
575 //TPythonDump()<<this<<".Destroy()";
578 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
580 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
581 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
584 ElementType Functor_i::GetElementType()
586 return ( ElementType )myFunctorPtr->GetType();
591 Class : NumericalFunctor_i
592 Description : Base class for numerical functors
594 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
596 return myNumericalFunctorPtr->GetValue( theId );
599 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
601 myNumericalFunctorPtr->SetPrecision( thePrecision );
602 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
605 CORBA::Long NumericalFunctor_i::GetPrecision()
607 return myNumericalFunctorPtr->GetPrecision();
610 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
612 return myNumericalFunctorPtr;
617 Class : SMESH_MinimumAngle
618 Description : Functor for calculation of minimum angle
620 MinimumAngle_i::MinimumAngle_i()
622 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
623 myFunctorPtr = myNumericalFunctorPtr;
626 FunctorType MinimumAngle_i::GetFunctorType()
628 return SMESH::FT_MinimumAngle;
634 Description : Functor for calculating aspect ratio
636 AspectRatio_i::AspectRatio_i()
638 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
639 myFunctorPtr = myNumericalFunctorPtr;
642 FunctorType AspectRatio_i::GetFunctorType()
644 return SMESH::FT_AspectRatio;
649 Class : AspectRatio3D
650 Description : Functor for calculating aspect ratio 3D
652 AspectRatio3D_i::AspectRatio3D_i()
654 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
655 myFunctorPtr = myNumericalFunctorPtr;
658 FunctorType AspectRatio3D_i::GetFunctorType()
660 return SMESH::FT_AspectRatio3D;
666 Description : Functor for calculating warping
668 Warping_i::Warping_i()
670 myNumericalFunctorPtr.reset( new Controls::Warping() );
671 myFunctorPtr = myNumericalFunctorPtr;
674 FunctorType Warping_i::GetFunctorType()
676 return SMESH::FT_Warping;
682 Description : Functor for calculating taper
686 myNumericalFunctorPtr.reset( new Controls::Taper() );
687 myFunctorPtr = myNumericalFunctorPtr;
690 FunctorType Taper_i::GetFunctorType()
692 return SMESH::FT_Taper;
698 Description : Functor for calculating skew in degrees
702 myNumericalFunctorPtr.reset( new Controls::Skew() );
703 myFunctorPtr = myNumericalFunctorPtr;
706 FunctorType Skew_i::GetFunctorType()
708 return SMESH::FT_Skew;
713 Description : Functor for calculating area
717 myNumericalFunctorPtr.reset( new Controls::Area() );
718 myFunctorPtr = myNumericalFunctorPtr;
721 FunctorType Area_i::GetFunctorType()
723 return SMESH::FT_Area;
728 Description : Functor for calculating volume of 3D element
730 Volume3D_i::Volume3D_i()
732 myNumericalFunctorPtr.reset( new Controls::Volume() );
733 myFunctorPtr = myNumericalFunctorPtr;
736 FunctorType Volume3D_i::GetFunctorType()
738 return SMESH::FT_Volume3D;
743 Description : Functor for calculating length off edge
747 myNumericalFunctorPtr.reset( new Controls::Length() );
748 myFunctorPtr = myNumericalFunctorPtr;
751 FunctorType Length_i::GetFunctorType()
753 return SMESH::FT_Length;
758 Description : Functor for calculating length of edge
760 Length2D_i::Length2D_i()
762 myNumericalFunctorPtr.reset( new Controls::Length2D() );
763 myFunctorPtr = myNumericalFunctorPtr;
766 FunctorType Length2D_i::GetFunctorType()
768 return SMESH::FT_Length2D;
771 SMESH::Length2D::Values* Length2D_i::GetValues()
773 INFOS("Length2D_i::GetValues");
774 SMESH::Controls::Length2D::TValues aValues;
775 myLength2DPtr->GetValues( aValues );
777 long i = 0, iEnd = aValues.size();
779 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
781 SMESH::Controls::Length2D::TValues::const_iterator anIter;
782 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
784 const SMESH::Controls::Length2D::Value& aVal = *anIter;
785 SMESH::Length2D::Value &aValue = aResult[ i ];
787 aValue.myLength = aVal.myLength;
788 aValue.myPnt1 = aVal.myPntId[ 0 ];
789 aValue.myPnt2 = aVal.myPntId[ 1 ];
792 INFOS("Length2D_i::GetValuess~");
793 return aResult._retn();
797 Class : MultiConnection_i
798 Description : Functor for calculating number of faces conneted to the edge
800 MultiConnection_i::MultiConnection_i()
802 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
803 myFunctorPtr = myNumericalFunctorPtr;
806 FunctorType MultiConnection_i::GetFunctorType()
808 return SMESH::FT_MultiConnection;
812 Class : MultiConnection2D_i
813 Description : Functor for calculating number of faces conneted to the edge
815 MultiConnection2D_i::MultiConnection2D_i()
817 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
818 myFunctorPtr = myNumericalFunctorPtr;
821 FunctorType MultiConnection2D_i::GetFunctorType()
823 return SMESH::FT_MultiConnection2D;
826 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
828 INFOS("MultiConnection2D_i::GetValues");
829 SMESH::Controls::MultiConnection2D::MValues aValues;
830 myMulticonnection2DPtr->GetValues( aValues );
832 long i = 0, iEnd = aValues.size();
834 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
836 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
837 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
839 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
840 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
842 aValue.myPnt1 = aVal.myPntId[ 0 ];
843 aValue.myPnt2 = aVal.myPntId[ 1 ];
844 aValue.myNbConnects = (*anIter).second;
847 INFOS("Multiconnection2D_i::GetValuess~");
848 return aResult._retn();
858 Description : Base class for all predicates
860 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
862 return myPredicatePtr->IsSatisfy( theId );
865 Controls::PredicatePtr Predicate_i::GetPredicate()
867 return myPredicatePtr;
871 Class : BadOrientedVolume_i
872 Description : Verify whether a mesh volume is incorrectly oriented from
873 the point of view of MED convention
875 BadOrientedVolume_i::BadOrientedVolume_i()
877 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
878 myFunctorPtr = myPredicatePtr = control;
881 FunctorType BadOrientedVolume_i::GetFunctorType()
883 return SMESH::FT_BadOrientedVolume;
887 Class : BelongToGeom_i
888 Description : Predicate for selection on geometrical support
890 BelongToGeom_i::BelongToGeom_i()
892 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
893 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
898 BelongToGeom_i::~BelongToGeom_i()
904 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
906 if ( theGeom->_is_nil() )
908 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
909 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
910 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
911 myBelongToGeomPtr->SetGeom( aLocShape );
912 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
915 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
917 myBelongToGeomPtr->SetGeom( theShape );
920 void BelongToGeom_i::SetElementType(ElementType theType){
921 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
922 TPythonDump()<<this<<".SetElementType("<<theType<<")";
925 FunctorType BelongToGeom_i::GetFunctorType()
927 return SMESH::FT_BelongToGeom;
930 void BelongToGeom_i::SetShapeName( const char* theName )
933 myShapeName = strdup( theName );
934 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
935 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
938 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
941 myShapeName = strdup( theName );
944 myShapeID = strdup( theID );
948 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
949 myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
951 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
954 char* BelongToGeom_i::GetShapeName()
956 return CORBA::string_dup( myShapeName );
959 char* BelongToGeom_i::GetShapeID()
961 return CORBA::string_dup( myShapeID );
964 void BelongToGeom_i::SetTolerance( CORBA::Double theToler )
966 myBelongToGeomPtr->SetTolerance( theToler );
967 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
970 CORBA::Double BelongToGeom_i::GetTolerance()
972 return myBelongToGeomPtr->GetTolerance();
976 Class : BelongToSurface_i
977 Description : Predicate for selection on geometrical support
979 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
981 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
982 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
985 mySurfaceType = theSurfaceType;
988 BelongToSurface_i::~BelongToSurface_i()
994 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
996 if ( theGeom->_is_nil() )
998 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
999 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1000 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1002 if ( aLocShape.ShapeType() == TopAbs_FACE )
1004 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
1005 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
1007 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1012 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
1015 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
1018 myShapeName = strdup( theName );
1019 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1020 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
1023 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
1026 myShapeName = strdup( theName );
1029 myShapeID = strdup( theID );
1033 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1034 myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
1036 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1039 char* BelongToSurface_i::GetShapeName()
1041 return CORBA::string_dup( myShapeName );
1044 char* BelongToSurface_i::GetShapeID()
1046 return CORBA::string_dup( myShapeID );
1049 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
1051 myElementsOnSurfacePtr->SetTolerance( theToler );
1052 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1055 CORBA::Double BelongToSurface_i::GetTolerance()
1057 return myElementsOnSurfacePtr->GetTolerance();
1060 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
1062 myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
1063 TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
1066 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
1068 return myElementsOnSurfacePtr->GetUseBoundaries();
1073 Class : BelongToPlane_i
1074 Description : Verify whether mesh element lie in pointed Geom planar object
1077 BelongToPlane_i::BelongToPlane_i()
1078 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
1082 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1084 BelongToSurface_i::SetSurface( theGeom, theType );
1085 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
1088 FunctorType BelongToPlane_i::GetFunctorType()
1090 return FT_BelongToPlane;
1094 Class : BelongToCylinder_i
1095 Description : Verify whether mesh element lie in pointed Geom planar object
1098 BelongToCylinder_i::BelongToCylinder_i()
1099 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1103 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1105 BelongToSurface_i::SetSurface( theGeom, theType );
1106 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
1109 FunctorType BelongToCylinder_i::GetFunctorType()
1111 return FT_BelongToCylinder;
1115 Class : BelongToGenSurface_i
1116 Description : Verify whether mesh element lie in pointed Geom planar object
1119 BelongToGenSurface_i::BelongToGenSurface_i()
1120 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1124 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1126 if ( theGeom->_is_nil() )
1128 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1129 if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1130 aLocShape.Nullify();
1132 BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1133 TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1136 FunctorType BelongToGenSurface_i::GetFunctorType()
1138 return FT_BelongToGenSurface;
1142 Class : LyingOnGeom_i
1143 Description : Predicate for selection on geometrical support
1145 LyingOnGeom_i::LyingOnGeom_i()
1147 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1148 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1153 LyingOnGeom_i::~LyingOnGeom_i()
1159 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1161 if ( theGeom->_is_nil() )
1163 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1164 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1165 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1166 myLyingOnGeomPtr->SetGeom( aLocShape );
1167 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1170 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1172 myLyingOnGeomPtr->SetGeom( theShape );
1175 void LyingOnGeom_i::SetElementType(ElementType theType){
1176 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1177 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1180 FunctorType LyingOnGeom_i::GetFunctorType()
1182 return SMESH::FT_LyingOnGeom;
1185 void LyingOnGeom_i::SetShapeName( const char* theName )
1188 myShapeName = strdup( theName );
1189 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1190 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1193 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1196 myShapeName = strdup( theName );
1199 myShapeID = strdup( theID );
1203 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1204 myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
1206 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1209 char* LyingOnGeom_i::GetShapeName()
1211 return CORBA::string_dup( myShapeName );
1214 char* LyingOnGeom_i::GetShapeID()
1216 return CORBA::string_dup( myShapeID );
1219 void LyingOnGeom_i::SetTolerance( CORBA::Double theToler )
1221 myLyingOnGeomPtr->SetTolerance( theToler );
1222 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1225 CORBA::Double LyingOnGeom_i::GetTolerance()
1227 return myLyingOnGeomPtr->GetTolerance();
1231 Class : FreeBorders_i
1232 Description : Predicate for free borders
1234 FreeBorders_i::FreeBorders_i()
1236 myPredicatePtr.reset(new Controls::FreeBorders());
1237 myFunctorPtr = myPredicatePtr;
1240 FunctorType FreeBorders_i::GetFunctorType()
1242 return SMESH::FT_FreeBorders;
1247 Description : Predicate for free borders
1249 FreeEdges_i::FreeEdges_i()
1250 : myFreeEdgesPtr( new Controls::FreeEdges() )
1252 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1255 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1257 INFOS("FreeEdges_i::GetBorders");
1258 SMESH::Controls::FreeEdges::TBorders aBorders;
1259 myFreeEdgesPtr->GetBoreders( aBorders );
1261 long i = 0, iEnd = aBorders.size();
1263 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1264 aResult->length(iEnd);
1266 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1267 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1269 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1270 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1272 aBorder.myElemId = aBord.myElemId;
1273 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1274 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1277 INFOS("FreeEdges_i::GetBorders~");
1278 return aResult._retn();
1281 FunctorType FreeEdges_i::GetFunctorType()
1283 return SMESH::FT_FreeEdges;
1288 Description : Predicate for free faces
1290 FreeFaces_i::FreeFaces_i()
1292 myPredicatePtr.reset(new Controls::FreeFaces());
1293 myFunctorPtr = myPredicatePtr;
1296 FunctorType FreeFaces_i::GetFunctorType()
1298 return SMESH::FT_FreeFaces;
1303 Description : Predicate for free nodes
1305 FreeNodes_i::FreeNodes_i()
1307 myPredicatePtr.reset(new Controls::FreeNodes());
1308 myFunctorPtr = myPredicatePtr;
1311 FunctorType FreeNodes_i::GetFunctorType()
1313 return SMESH::FT_FreeNodes;
1317 Class : RangeOfIds_i
1318 Description : Predicate for Range of Ids.
1319 Range may be specified with two ways.
1320 1. Using AddToRange method
1321 2. With SetRangeStr method. Parameter of this method is a string
1322 like as "1,2,3,50-60,63,67,70-"
1325 RangeOfIds_i::RangeOfIds_i()
1327 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1328 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1331 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1333 CORBA::Long iEnd = theIds.length();
1334 for ( CORBA::Long i = 0; i < iEnd; i++ )
1335 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1336 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1339 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1341 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1342 return myRangeOfIdsPtr->SetRangeStr(
1343 TCollection_AsciiString( (Standard_CString)theRange ) );
1346 char* RangeOfIds_i::GetRangeStr()
1348 TCollection_AsciiString aStr;
1349 myRangeOfIdsPtr->GetRangeStr( aStr );
1350 return CORBA::string_dup( aStr.ToCString() );
1353 void RangeOfIds_i::SetElementType( ElementType theType )
1355 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1356 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1359 FunctorType RangeOfIds_i::GetFunctorType()
1361 return SMESH::FT_RangeOfIds;
1365 Class : LinearOrQuadratic_i
1366 Description : Predicate to verify whether a mesh element is linear
1368 LinearOrQuadratic_i::LinearOrQuadratic_i()
1370 myLinearOrQuadraticPtr.reset(new Controls::LinearOrQuadratic());
1371 myFunctorPtr = myPredicatePtr = myLinearOrQuadraticPtr;
1374 void LinearOrQuadratic_i::SetElementType(ElementType theType)
1376 myLinearOrQuadraticPtr->SetType(SMDSAbs_ElementType(theType));
1377 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1380 FunctorType LinearOrQuadratic_i::GetFunctorType()
1382 return SMESH::FT_LinearOrQuadratic;
1386 Class : GroupColor_i
1387 Description : Functor for check color of group to whic mesh element belongs to
1389 GroupColor_i::GroupColor_i()
1391 myGroupColorPtr.reset(new Controls::GroupColor());
1392 myFunctorPtr = myPredicatePtr = myGroupColorPtr;
1395 FunctorType GroupColor_i::GetFunctorType()
1397 return SMESH::FT_GroupColor;
1400 void GroupColor_i::SetColorStr( const char* theColor )
1402 myGroupColorPtr->SetColorStr(
1403 TCollection_AsciiString( (Standard_CString)theColor ) );
1404 TPythonDump()<<this<<".SetColorStr('"<<theColor<<"')";
1407 char* GroupColor_i::GetColorStr()
1409 TCollection_AsciiString aStr;
1410 myGroupColorPtr->GetColorStr( aStr );
1411 return CORBA::string_dup( aStr.ToCString() );
1414 void GroupColor_i::SetElementType(ElementType theType)
1416 myGroupColorPtr->SetType(SMDSAbs_ElementType(theType));
1417 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1421 Class : ElemGeomType_i
1422 Description : Predicate check is element has indicated geometry type
1424 ElemGeomType_i::ElemGeomType_i()
1426 myElemGeomTypePtr.reset(new Controls::ElemGeomType());
1427 myFunctorPtr = myPredicatePtr = myElemGeomTypePtr;
1430 void ElemGeomType_i::SetElementType(ElementType theType)
1432 myElemGeomTypePtr->SetType(SMDSAbs_ElementType(theType));
1433 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1436 void ElemGeomType_i::SetGeometryType(GeometryType theType)
1438 myElemGeomTypePtr->SetGeomType(SMDSAbs_GeometryType(theType));
1439 TPythonDump()<<this<<".SetGeometryType("<<theType<<")";
1442 GeometryType ElemGeomType_i::GetGeometryType() const
1444 return (GeometryType)myElemGeomTypePtr->GetGeomType();;
1447 FunctorType ElemGeomType_i::GetFunctorType()
1449 return SMESH::FT_ElemGeomType;
1453 Class : Comparator_i
1454 Description : Base class for comparators
1456 Comparator_i::Comparator_i():
1457 myNumericalFunctor( NULL )
1460 Comparator_i::~Comparator_i()
1462 if ( myNumericalFunctor )
1463 myNumericalFunctor->Destroy();
1466 void Comparator_i::SetMargin( CORBA::Double theValue )
1468 myComparatorPtr->SetMargin( theValue );
1469 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1472 CORBA::Double Comparator_i::GetMargin()
1474 return myComparatorPtr->GetMargin();
1477 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1479 if ( myNumericalFunctor )
1480 myNumericalFunctor->Destroy();
1482 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1484 if ( myNumericalFunctor )
1486 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1487 myNumericalFunctor->Register();
1488 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1492 Controls::ComparatorPtr Comparator_i::GetComparator()
1494 return myComparatorPtr;
1497 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1499 return myNumericalFunctor;
1505 Description : Comparator "<"
1507 LessThan_i::LessThan_i()
1509 myComparatorPtr.reset( new Controls::LessThan() );
1510 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1513 FunctorType LessThan_i::GetFunctorType()
1515 return SMESH::FT_LessThan;
1521 Description : Comparator ">"
1523 MoreThan_i::MoreThan_i()
1525 myComparatorPtr.reset( new Controls::MoreThan() );
1526 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1529 FunctorType MoreThan_i::GetFunctorType()
1531 return SMESH::FT_MoreThan;
1537 Description : Comparator "="
1539 EqualTo_i::EqualTo_i()
1540 : myEqualToPtr( new Controls::EqualTo() )
1542 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1545 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1547 myEqualToPtr->SetTolerance( theToler );
1548 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1551 CORBA::Double EqualTo_i::GetTolerance()
1553 return myEqualToPtr->GetTolerance();
1556 FunctorType EqualTo_i::GetFunctorType()
1558 return SMESH::FT_EqualTo;
1562 Class : LogicalNOT_i
1563 Description : Logical NOT predicate
1565 LogicalNOT_i::LogicalNOT_i()
1566 : myPredicate( NULL ),
1567 myLogicalNOTPtr( new Controls::LogicalNOT() )
1569 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1572 LogicalNOT_i::~LogicalNOT_i()
1575 myPredicate->Destroy();
1578 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1581 myPredicate->Destroy();
1583 myPredicate = SMESH::GetPredicate(thePredicate);
1586 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1587 myPredicate->Register();
1588 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1592 FunctorType LogicalNOT_i::GetFunctorType()
1594 return SMESH::FT_LogicalNOT;
1597 Predicate_i* LogicalNOT_i::GetPredicate_i()
1604 Class : LogicalBinary_i
1605 Description : Base class for binary logical predicate
1607 LogicalBinary_i::LogicalBinary_i()
1608 : myPredicate1( NULL ),
1609 myPredicate2( NULL )
1612 LogicalBinary_i::~LogicalBinary_i()
1615 myPredicate1->Destroy();
1618 myPredicate2->Destroy();
1621 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1624 myPredicate1->SetMesh( theMesh );
1627 myPredicate2->SetMesh( theMesh );
1630 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1633 myPredicate1->Destroy();
1635 myPredicate1 = SMESH::GetPredicate(thePredicate);
1637 if ( myPredicate1 ){
1638 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1639 myPredicate1->Register();
1640 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1644 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1647 myPredicate2->Destroy();
1649 myPredicate2 = SMESH::GetPredicate(thePredicate);
1651 if ( myPredicate2 ){
1652 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1653 myPredicate2->Register();
1654 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1658 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1660 return myLogicalBinaryPtr;
1663 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1665 return myPredicate1;
1667 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1669 return myPredicate2;
1674 Class : LogicalAND_i
1675 Description : Logical AND
1677 LogicalAND_i::LogicalAND_i()
1679 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1680 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1683 FunctorType LogicalAND_i::GetFunctorType()
1685 return SMESH::FT_LogicalAND;
1691 Description : Logical OR
1693 LogicalOR_i::LogicalOR_i()
1695 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1696 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1699 FunctorType LogicalOR_i::GetFunctorType()
1701 return SMESH::FT_LogicalOR;
1709 FilterManager_i::FilterManager_i()
1710 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1712 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
1713 //PortableServer::ObjectId_var anObjectId =
1714 // SMESH_Gen_i::GetPOA()->activate_object( this );
1718 FilterManager_i::~FilterManager_i()
1720 //TPythonDump()<<this<<".Destroy()";
1724 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1726 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1727 SMESH::MinimumAngle_var anObj = aServant->_this();
1728 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1729 return anObj._retn();
1733 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1735 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1736 SMESH::AspectRatio_var anObj = aServant->_this();
1737 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1738 return anObj._retn();
1742 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1744 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1745 SMESH::AspectRatio3D_var anObj = aServant->_this();
1746 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1747 return anObj._retn();
1751 Warping_ptr FilterManager_i::CreateWarping()
1753 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1754 SMESH::Warping_var anObj = aServant->_this();
1755 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1756 return anObj._retn();
1760 Taper_ptr FilterManager_i::CreateTaper()
1762 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1763 SMESH::Taper_var anObj = aServant->_this();
1764 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1765 return anObj._retn();
1769 Skew_ptr FilterManager_i::CreateSkew()
1771 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1772 SMESH::Skew_var anObj = aServant->_this();
1773 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1774 return anObj._retn();
1778 Area_ptr FilterManager_i::CreateArea()
1780 SMESH::Area_i* aServant = new SMESH::Area_i();
1781 SMESH::Area_var anObj = aServant->_this();
1782 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1783 return anObj._retn();
1787 Volume3D_ptr FilterManager_i::CreateVolume3D()
1789 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
1790 SMESH::Volume3D_var anObj = aServant->_this();
1791 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
1792 return anObj._retn();
1796 Length_ptr FilterManager_i::CreateLength()
1798 SMESH::Length_i* aServant = new SMESH::Length_i();
1799 SMESH::Length_var anObj = aServant->_this();
1800 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1801 return anObj._retn();
1804 Length2D_ptr FilterManager_i::CreateLength2D()
1806 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1807 SMESH::Length2D_var anObj = aServant->_this();
1808 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1809 return anObj._retn();
1812 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1814 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1815 SMESH::MultiConnection_var anObj = aServant->_this();
1816 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1817 return anObj._retn();
1820 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1822 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1823 SMESH::MultiConnection2D_var anObj = aServant->_this();
1824 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
1825 return anObj._retn();
1828 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1830 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1831 SMESH::BelongToGeom_var anObj = aServant->_this();
1832 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
1833 return anObj._retn();
1836 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1838 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1839 SMESH::BelongToPlane_var anObj = aServant->_this();
1840 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
1841 return anObj._retn();
1844 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1846 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1847 SMESH::BelongToCylinder_var anObj = aServant->_this();
1848 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
1849 return anObj._retn();
1852 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
1854 SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
1855 SMESH::BelongToGenSurface_var anObj = aServant->_this();
1856 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
1857 return anObj._retn();
1860 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
1862 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
1863 SMESH::LyingOnGeom_var anObj = aServant->_this();
1864 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
1865 return anObj._retn();
1868 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1870 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1871 SMESH::FreeBorders_var anObj = aServant->_this();
1872 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
1873 return anObj._retn();
1876 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1878 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1879 SMESH::FreeEdges_var anObj = aServant->_this();
1880 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
1881 return anObj._retn();
1884 FreeFaces_ptr FilterManager_i::CreateFreeFaces()
1886 SMESH::FreeFaces_i* aServant = new SMESH::FreeFaces_i();
1887 SMESH::FreeFaces_var anObj = aServant->_this();
1888 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeFaces()";
1889 return anObj._retn();
1892 FreeNodes_ptr FilterManager_i::CreateFreeNodes()
1894 SMESH::FreeNodes_i* aServant = new SMESH::FreeNodes_i();
1895 SMESH::FreeNodes_var anObj = aServant->_this();
1896 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeNodes()";
1897 return anObj._retn();
1900 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1902 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1903 SMESH::RangeOfIds_var anObj = aServant->_this();
1904 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
1905 return anObj._retn();
1908 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
1910 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
1911 SMESH::BadOrientedVolume_var anObj = aServant->_this();
1912 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
1913 return anObj._retn();
1916 LessThan_ptr FilterManager_i::CreateLessThan()
1918 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1919 SMESH::LessThan_var anObj = aServant->_this();
1920 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
1921 return anObj._retn();
1924 MoreThan_ptr FilterManager_i::CreateMoreThan()
1926 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1927 SMESH::MoreThan_var anObj = aServant->_this();
1928 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
1929 return anObj._retn();
1932 EqualTo_ptr FilterManager_i::CreateEqualTo()
1934 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1935 SMESH::EqualTo_var anObj = aServant->_this();
1936 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
1937 return anObj._retn();
1940 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1942 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1943 SMESH::LogicalNOT_var anObj = aServant->_this();
1944 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
1945 return anObj._retn();
1948 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
1950 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
1951 SMESH::LogicalAND_var anObj = aServant->_this();
1952 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
1953 return anObj._retn();
1956 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
1958 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
1959 SMESH::LogicalOR_var anObj = aServant->_this();
1960 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
1961 return anObj._retn();
1964 LinearOrQuadratic_ptr FilterManager_i::CreateLinearOrQuadratic()
1966 SMESH::LinearOrQuadratic_i* aServant = new SMESH::LinearOrQuadratic_i();
1967 SMESH::LinearOrQuadratic_var anObj = aServant->_this();
1968 TPythonDump()<<aServant<<" = "<<this<<".CreateLinearOrQuadratic()";
1969 return anObj._retn();
1972 GroupColor_ptr FilterManager_i::CreateGroupColor()
1974 SMESH::GroupColor_i* aServant = new SMESH::GroupColor_i();
1975 SMESH::GroupColor_var anObj = aServant->_this();
1976 TPythonDump()<<aServant<<" = "<<this<<".CreateGroupColor()";
1977 return anObj._retn();
1980 ElemGeomType_ptr FilterManager_i::CreateElemGeomType()
1982 SMESH::ElemGeomType_i* aServant = new SMESH::ElemGeomType_i();
1983 SMESH::ElemGeomType_var anObj = aServant->_this();
1984 TPythonDump()<<aServant<<" = "<<this<<".CreateElemGeomType()";
1985 return anObj._retn();
1988 Filter_ptr FilterManager_i::CreateFilter()
1990 SMESH::Filter_i* aServant = new SMESH::Filter_i();
1991 SMESH::Filter_var anObj = aServant->_this();
1992 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
1993 return anObj._retn();
1996 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
1998 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
1999 SMESH::FilterLibrary_var anObj = aServant->_this();
2000 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary('"<<aFileName<<"')";
2001 return anObj._retn();
2004 FilterLibrary_ptr FilterManager_i::CreateLibrary()
2006 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
2007 SMESH::FilterLibrary_var anObj = aServant->_this();
2008 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
2009 return anObj._retn();
2012 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
2014 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
2015 return remove( aFileName ) ? false : true;
2018 //=============================================================================
2020 * SMESH_Gen_i::CreateFilterManager
2022 * Create filter manager
2024 //=============================================================================
2026 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
2028 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2029 SMESH::FilterManager_var anObj = aFilter->_this();
2030 return anObj._retn();
2038 //=======================================================================
2039 // name : Filter_i::Filter_i
2040 // Purpose : Constructor
2041 //=======================================================================
2042 Filter_i::Filter_i()
2043 : myPredicate( NULL )
2046 //=======================================================================
2047 // name : Filter_i::~Filter_i
2048 // Purpose : Destructor
2049 //=======================================================================
2050 Filter_i::~Filter_i()
2053 myPredicate->Destroy();
2055 if(!CORBA::is_nil(myMesh))
2058 //TPythonDump()<<this<<".Destroy()";
2061 //=======================================================================
2062 // name : Filter_i::SetPredicate
2063 // Purpose : Set predicate
2064 //=======================================================================
2065 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
2068 myPredicate->Destroy();
2070 myPredicate = SMESH::GetPredicate(thePredicate);
2074 myFilter.SetPredicate( myPredicate->GetPredicate() );
2075 myPredicate->Register();
2076 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
2080 //=======================================================================
2081 // name : Filter_i::GetElementType
2082 // Purpose : Get entity type
2083 //=======================================================================
2084 SMESH::ElementType Filter_i::GetElementType()
2086 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
2089 //=======================================================================
2090 // name : Filter_i::SetMesh
2091 // Purpose : Set mesh
2092 //=======================================================================
2095 SetMesh( SMESH_Mesh_ptr theMesh )
2097 if(!CORBA::is_nil(theMesh))
2098 theMesh->Register();
2100 if(!CORBA::is_nil(myMesh))
2103 myMesh = SMESH_Mesh::_duplicate( theMesh );
2104 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
2111 return GetElementsId(myMesh);
2114 //=======================================================================
2115 // name : Filter_i::GetElementsId
2116 // Purpose : Get ids of entities
2117 //=======================================================================
2120 GetElementsId( Predicate_i* thePredicate,
2121 const SMDS_Mesh* theMesh,
2122 Controls::Filter::TIdSequence& theSequence )
2125 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
2130 GetElementsId( Predicate_i* thePredicate,
2131 SMESH_Mesh_ptr theMesh,
2132 Controls::Filter::TIdSequence& theSequence )
2135 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2136 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
2141 GetElementsId( SMESH_Mesh_ptr theMesh )
2143 SMESH::long_array_var anArray = new SMESH::long_array;
2144 if(!CORBA::is_nil(theMesh) && myPredicate){
2145 Controls::Filter::TIdSequence aSequence;
2146 GetElementsId(myPredicate,theMesh,aSequence);
2147 long i = 0, iEnd = aSequence.size();
2148 anArray->length( iEnd );
2149 for ( ; i < iEnd; i++ )
2150 anArray[ i ] = aSequence[i];
2152 return anArray._retn();
2155 template<class TElement, class TIterator, class TPredicate>
2156 static void collectMeshInfo(const TIterator& theItr,
2157 TPredicate& thePred,
2158 SMESH::long_array& theRes)
2162 while (theItr->more()) {
2163 const SMDS_MeshElement* anElem = theItr->next();
2164 if ( thePred->IsSatisfy( anElem->GetID() ) )
2165 theRes[ anElem->GetEntityType() ]++;
2169 //=============================================================================
2171 * \brief Returns statistic of mesh elements
2173 //=============================================================================
2174 SMESH::long_array* ::Filter_i::GetMeshInfo()
2176 SMESH::long_array_var aRes = new SMESH::long_array();
2177 aRes->length(SMESH::Entity_Last);
2178 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
2181 if(!CORBA::is_nil(myMesh) && myPredicate) {
2182 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2183 SMDS_ElemIteratorPtr it;
2184 switch( GetElementType() )
2187 collectMeshInfo<const SMDS_MeshNode*>(aMesh->nodesIterator(),myPredicate,aRes);
2190 collectMeshInfo<const SMDS_MeshElement*>(aMesh->edgesIterator(),myPredicate,aRes);
2193 collectMeshInfo<const SMDS_MeshElement*>(aMesh->facesIterator(),myPredicate,aRes);
2195 case SMDSAbs_Volume:
2196 collectMeshInfo<const SMDS_MeshElement*>(aMesh->volumesIterator(),myPredicate,aRes);
2200 collectMeshInfo<const SMDS_MeshElement*>(aMesh->elementsIterator(),myPredicate,aRes);
2206 return aRes._retn();
2209 //================================================================================
2211 * \brief Return GetElementType() within an array
2212 * Implement SMESH_IDSource interface
2214 //================================================================================
2216 SMESH::array_of_ElementType* Filter_i::GetTypes()
2218 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
2220 types[0] = GetElementType();
2221 return types._retn();
2224 //=======================================================================
2225 // name : getCriteria
2226 // Purpose : Retrieve criterions from predicate
2227 //=======================================================================
2228 static inline bool getCriteria( Predicate_i* thePred,
2229 SMESH::Filter::Criteria_out theCriteria )
2231 int aFType = thePred->GetFunctorType();
2235 case FT_FreeBorders:
2238 case FT_LinearOrQuadratic:
2241 CORBA::ULong i = theCriteria->length();
2242 theCriteria->length( i + 1 );
2244 theCriteria[ i ] = createCriterion();
2246 theCriteria[ i ].Type = aFType;
2247 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
2250 case FT_BelongToGeom:
2252 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
2254 CORBA::ULong i = theCriteria->length();
2255 theCriteria->length( i + 1 );
2257 theCriteria[ i ] = createCriterion();
2259 theCriteria[ i ].Type = FT_BelongToGeom;
2260 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2261 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2262 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2263 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2267 case FT_BelongToPlane:
2268 case FT_BelongToCylinder:
2269 case FT_BelongToGenSurface:
2271 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
2273 CORBA::ULong i = theCriteria->length();
2274 theCriteria->length( i + 1 );
2276 theCriteria[ i ] = createCriterion();
2278 theCriteria[ i ].Type = aFType;
2279 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2280 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2281 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2282 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2286 case FT_LyingOnGeom:
2288 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
2290 CORBA::ULong i = theCriteria->length();
2291 theCriteria->length( i + 1 );
2293 theCriteria[ i ] = createCriterion();
2295 theCriteria[ i ].Type = FT_LyingOnGeom;
2296 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2297 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2298 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2299 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2305 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
2307 CORBA::ULong i = theCriteria->length();
2308 theCriteria->length( i + 1 );
2310 theCriteria[ i ] = createCriterion();
2312 theCriteria[ i ].Type = FT_RangeOfIds;
2313 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
2314 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2318 case FT_BadOrientedVolume:
2320 BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
2322 CORBA::ULong i = theCriteria->length();
2323 theCriteria->length( i + 1 );
2325 theCriteria[ i ] = createCriterion();
2327 theCriteria[ i ].Type = FT_BadOrientedVolume;
2328 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2336 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
2338 CORBA::ULong i = theCriteria->length();
2339 theCriteria->length( i + 1 );
2341 theCriteria[ i ] = createCriterion();
2343 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
2344 theCriteria[ i ].Compare = aFType;
2345 theCriteria[ i ].Threshold = aCompar->GetMargin();
2346 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
2348 if ( aFType == FT_EqualTo )
2350 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
2351 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
2358 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2359 getCriteria( aPred, theCriteria );
2360 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2367 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2368 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2369 if ( !getCriteria( aPred1, theCriteria ) )
2371 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2372 return getCriteria( aPred2, theCriteria );
2376 CORBA::ULong i = theCriteria->length();
2377 theCriteria->length( i + 1 );
2379 theCriteria[ i ] = createCriterion();
2381 GroupColor_i* aPred = dynamic_cast<GroupColor_i*>( thePred );
2382 theCriteria[ i ].Type = aFType;
2383 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2384 theCriteria[ i ].ThresholdStr = aPred->GetColorStr();
2388 case FT_ElemGeomType:
2390 CORBA::ULong i = theCriteria->length();
2391 theCriteria->length( i + 1 );
2393 theCriteria[ i ] = createCriterion();
2395 ElemGeomType_i* aPred = dynamic_cast<ElemGeomType_i*>( thePred );
2396 theCriteria[ i ].Type = aFType;
2397 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2398 theCriteria[ i ].Threshold = (double)aPred->GetGeometryType();
2409 //=======================================================================
2410 // name : Filter_i::GetCriteria
2411 // Purpose : Retrieve criterions from predicate
2412 //=======================================================================
2413 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2415 theCriteria = new SMESH::Filter::Criteria;
2416 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2419 //=======================================================================
2420 // name : Filter_i::SetCriteria
2421 // Purpose : Create new predicate and set criterions in it
2422 //=======================================================================
2423 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2425 if ( myPredicate != 0 )
2426 myPredicate->Destroy();
2428 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2429 FilterManager_ptr aFilterMgr = aFilter->_this();
2431 // CREATE two lists ( PREDICATES and LOG OP )
2434 TPythonDump()<<"aCriteria = []";
2435 std::list<SMESH::Predicate_ptr> aPredicates;
2436 std::list<int> aBinaries;
2437 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2439 int aCriterion = theCriteria[ i ].Type;
2440 int aCompare = theCriteria[ i ].Compare;
2441 double aThreshold = theCriteria[ i ].Threshold;
2442 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2443 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2444 int aUnary = theCriteria[ i ].UnaryOp;
2445 int aBinary = theCriteria[ i ].BinaryOp;
2446 double aTolerance = theCriteria[ i ].Tolerance;
2447 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
2448 long aPrecision = theCriteria[ i ].Precision;
2452 pd << "aCriterion = SMESH.Filter.Criterion(" << aCriterion << "," << aCompare
2453 << "," << aThreshold << ",'" << aThresholdStr;
2454 if (aThresholdID && strlen(aThresholdID))
2455 //pd << "',salome.ObjectToID(" << aThresholdID
2456 pd << "','" << aThresholdID
2457 << "'," << aUnary << "," << aBinary << "," << aTolerance
2458 << "," << aTypeOfElem << "," << aPrecision << ")";
2460 pd << "',''," << aUnary << "," << aBinary << "," << aTolerance
2461 << "," << aTypeOfElem << "," << aPrecision << ")";
2464 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2465 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2467 switch ( aCriterion )
2471 case SMESH::FT_MultiConnection:
2472 aFunctor = aFilterMgr->CreateMultiConnection();
2474 case SMESH::FT_MultiConnection2D:
2475 aFunctor = aFilterMgr->CreateMultiConnection2D();
2477 case SMESH::FT_Length:
2478 aFunctor = aFilterMgr->CreateLength();
2480 case SMESH::FT_Length2D:
2481 aFunctor = aFilterMgr->CreateLength2D();
2483 case SMESH::FT_AspectRatio:
2484 aFunctor = aFilterMgr->CreateAspectRatio();
2486 case SMESH::FT_AspectRatio3D:
2487 aFunctor = aFilterMgr->CreateAspectRatio3D();
2489 case SMESH::FT_Warping:
2490 aFunctor = aFilterMgr->CreateWarping();
2492 case SMESH::FT_MinimumAngle:
2493 aFunctor = aFilterMgr->CreateMinimumAngle();
2495 case SMESH::FT_Taper:
2496 aFunctor = aFilterMgr->CreateTaper();
2498 case SMESH::FT_Skew:
2499 aFunctor = aFilterMgr->CreateSkew();
2501 case SMESH::FT_Area:
2502 aFunctor = aFilterMgr->CreateArea();
2504 case SMESH::FT_Volume3D:
2505 aFunctor = aFilterMgr->CreateVolume3D();
2510 case SMESH::FT_FreeBorders:
2511 aPredicate = aFilterMgr->CreateFreeBorders();
2513 case SMESH::FT_FreeEdges:
2514 aPredicate = aFilterMgr->CreateFreeEdges();
2516 case SMESH::FT_FreeFaces:
2517 aPredicate = aFilterMgr->CreateFreeFaces();
2519 case SMESH::FT_FreeNodes:
2520 aPredicate = aFilterMgr->CreateFreeNodes();
2522 case SMESH::FT_BelongToGeom:
2524 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2525 tmpPred->SetElementType( aTypeOfElem );
2526 tmpPred->SetShape( aThresholdID, aThresholdStr );
2527 tmpPred->SetTolerance( aTolerance );
2528 aPredicate = tmpPred;
2531 case SMESH::FT_BelongToPlane:
2532 case SMESH::FT_BelongToCylinder:
2533 case SMESH::FT_BelongToGenSurface:
2535 SMESH::BelongToSurface_ptr tmpPred;
2536 switch ( aCriterion ) {
2537 case SMESH::FT_BelongToPlane:
2538 tmpPred = aFilterMgr->CreateBelongToPlane(); break;
2539 case SMESH::FT_BelongToCylinder:
2540 tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
2542 tmpPred = aFilterMgr->CreateBelongToGenSurface();
2544 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2545 tmpPred->SetTolerance( aTolerance );
2546 aPredicate = tmpPred;
2549 case SMESH::FT_LyingOnGeom:
2551 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2552 tmpPred->SetElementType( aTypeOfElem );
2553 tmpPred->SetShape( aThresholdID, aThresholdStr );
2554 tmpPred->SetTolerance( aTolerance );
2555 aPredicate = tmpPred;
2558 case SMESH::FT_RangeOfIds:
2560 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2561 tmpPred->SetRangeStr( aThresholdStr );
2562 tmpPred->SetElementType( aTypeOfElem );
2563 aPredicate = tmpPred;
2566 case SMESH::FT_BadOrientedVolume:
2568 aPredicate = aFilterMgr->CreateBadOrientedVolume();
2571 case SMESH::FT_LinearOrQuadratic:
2573 SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
2574 tmpPred->SetElementType( aTypeOfElem );
2575 aPredicate = tmpPred;
2578 case SMESH::FT_GroupColor:
2580 SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor();
2581 tmpPred->SetElementType( aTypeOfElem );
2582 tmpPred->SetColorStr( aThresholdStr );
2583 aPredicate = tmpPred;
2586 case SMESH::FT_ElemGeomType:
2588 SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType();
2589 tmpPred->SetElementType( aTypeOfElem );
2590 tmpPred->SetGeometryType( (GeometryType)(int)(aThreshold + 0.5) );
2591 aPredicate = tmpPred;
2600 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
2602 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
2604 if ( aCompare == SMESH::FT_LessThan )
2605 aComparator = aFilterMgr->CreateLessThan();
2606 else if ( aCompare == SMESH::FT_MoreThan )
2607 aComparator = aFilterMgr->CreateMoreThan();
2608 else if ( aCompare == SMESH::FT_EqualTo )
2609 aComparator = aFilterMgr->CreateEqualTo();
2613 aComparator->SetNumFunctor( aFunctor );
2614 aComparator->SetMargin( aThreshold );
2616 if ( aCompare == FT_EqualTo )
2618 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
2619 anEqualTo->SetTolerance( aTolerance );
2622 aPredicate = aComparator;
2624 aFunctor->SetPrecision( aPrecision );
2628 if ( aUnary == FT_LogicalNOT )
2630 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
2631 aNotPred->SetPredicate( aPredicate );
2632 aPredicate = aNotPred;
2636 aPredicates.push_back( aPredicate );
2637 aBinaries.push_back( aBinary );
2638 TPythonDump()<<"aCriteria.append(aCriterion)";
2641 TPythonDump()<<this<<".SetCriteria(aCriteria)";
2643 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
2645 // combine all "AND" operations
2647 std::list<SMESH::Predicate_ptr> aResList;
2649 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
2650 std::list<int>::iterator aBinaryIter;
2652 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
2653 int aPrevBinary = SMESH::FT_Undefined;
2655 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
2656 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
2657 ++aPredIter, ++aBinaryIter )
2659 int aCurrBinary = *aBinaryIter;
2661 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
2663 if ( aPrevBinary == SMESH::FT_LogicalAND )
2666 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2667 aBinaryPred->SetPredicate1( aPrevPredicate );
2668 aBinaryPred->SetPredicate2( *aPredIter );
2669 aCurrPred = aBinaryPred;
2672 aCurrPred = *aPredIter;
2674 if ( aCurrBinary != SMESH::FT_LogicalAND )
2675 aResList.push_back( aCurrPred );
2677 aPrevPredicate = aCurrPred;
2678 aPrevBinary = aCurrBinary;
2681 // combine all "OR" operations
2683 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2685 if ( aResList.size() == 1 )
2686 aResPredicate = *aResList.begin();
2687 else if ( aResList.size() > 1 )
2689 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2690 aResPredicate = *anIter;
2692 for ( ; anIter != aResList.end(); ++anIter )
2694 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2695 aBinaryPred->SetPredicate1( aResPredicate );
2696 aBinaryPred->SetPredicate2( *anIter );
2697 aResPredicate = aBinaryPred;
2701 SetPredicate( aResPredicate );
2703 return !aResPredicate->_is_nil();
2706 //=======================================================================
2707 // name : Filter_i::GetPredicate_i
2708 // Purpose : Get implementation of predicate
2709 //=======================================================================
2710 Predicate_i* Filter_i::GetPredicate_i()
2715 //=======================================================================
2716 // name : Filter_i::GetPredicate
2717 // Purpose : Get predicate
2718 //=======================================================================
2719 Predicate_ptr Filter_i::GetPredicate()
2721 if ( myPredicate == 0 )
2722 return SMESH::Predicate::_nil();
2725 SMESH::Predicate_var anObj = myPredicate->_this();
2726 return anObj._retn();
2734 #define ATTR_TYPE "type"
2735 #define ATTR_COMPARE "compare"
2736 #define ATTR_THRESHOLD "threshold"
2737 #define ATTR_UNARY "unary"
2738 #define ATTR_BINARY "binary"
2739 #define ATTR_THRESHOLD_STR "threshold_str"
2740 #define ATTR_TOLERANCE "tolerance"
2741 #define ATTR_ELEMENT_TYPE "ElementType"
2743 //=======================================================================
2745 // Purpose : Convert bool to LDOMString
2746 //=======================================================================
2747 static inline LDOMString toString( CORBA::Boolean val )
2749 return val ? "logical not" : "";
2752 //=======================================================================
2754 // Purpose : Convert LDOMString to bool
2755 //=======================================================================
2756 static inline bool toBool( const LDOMString& theStr )
2758 return theStr.equals( "logical not" );
2761 //=======================================================================
2763 // Purpose : Convert double to LDOMString
2764 //=======================================================================
2765 static inline LDOMString toString( CORBA::Double val )
2768 sprintf( a, "%e", val );
2769 return LDOMString( a );
2772 //=======================================================================
2774 // Purpose : Convert LDOMString to double
2775 //=======================================================================
2776 static inline double toDouble( const LDOMString& theStr )
2778 return atof( theStr.GetString() );
2781 //=======================================================================
2783 // Purpose : Convert functor type to LDOMString
2784 //=======================================================================
2785 static inline LDOMString toString( CORBA::Long theType )
2789 case FT_AspectRatio : return "Aspect ratio";
2790 case FT_Warping : return "Warping";
2791 case FT_MinimumAngle : return "Minimum angle";
2792 case FT_Taper : return "Taper";
2793 case FT_Skew : return "Skew";
2794 case FT_Area : return "Area";
2795 case FT_Volume3D : return "Volume3D";
2796 case FT_BelongToGeom : return "Belong to Geom";
2797 case FT_BelongToPlane : return "Belong to Plane";
2798 case FT_BelongToCylinder: return "Belong to Cylinder";
2799 case FT_BelongToGenSurface: return "Belong to Generic Surface";
2800 case FT_LyingOnGeom : return "Lying on Geom";
2801 case FT_BadOrientedVolume: return "Bad Oriented Volume";
2802 case FT_RangeOfIds : return "Range of IDs";
2803 case FT_FreeBorders : return "Free borders";
2804 case FT_FreeEdges : return "Free edges";
2805 case FT_FreeFaces : return "Free faces";
2806 case FT_FreeNodes : return "Free nodes";
2807 case FT_MultiConnection : return "Borders at multi-connections";
2808 case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2809 case FT_Length : return "Length";
2810 case FT_Length2D : return "Length 2D";
2811 case FT_LessThan : return "Less than";
2812 case FT_MoreThan : return "More than";
2813 case FT_EqualTo : return "Equal to";
2814 case FT_LogicalNOT : return "Not";
2815 case FT_LogicalAND : return "And";
2816 case FT_LogicalOR : return "Or";
2817 case FT_GroupColor : return "Color of Group";
2818 case FT_LinearOrQuadratic : return "Linear or Quadratic";
2819 case FT_ElemGeomType : return "Element geomtry type";
2820 case FT_Undefined : return "";
2821 default : return "";
2825 //=======================================================================
2826 // name : toFunctorType
2827 // Purpose : Convert LDOMString to functor type
2828 //=======================================================================
2829 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
2831 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
2832 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
2833 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
2834 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
2835 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
2836 else if ( theStr.equals( "Area" ) ) return FT_Area;
2837 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
2838 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
2839 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
2840 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
2841 else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface;
2842 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
2843 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
2844 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
2845 else if ( theStr.equals( "Free faces" ) ) return FT_FreeFaces;
2846 else if ( theStr.equals( "Free nodes" ) ) return FT_FreeNodes;
2847 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
2848 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
2849 else if ( theStr.equals( "Length" ) ) return FT_Length;
2850 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
2851 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
2852 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
2853 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
2854 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
2855 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
2856 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
2857 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
2858 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
2859 else if ( theStr.equals( "Color of Group" ) ) return FT_GroupColor;
2860 else if ( theStr.equals( "Linear or Quadratic" ) ) return FT_LinearOrQuadratic;
2861 else if ( theStr.equals( "Element geomtry type" ) ) return FT_ElemGeomType;
2862 else if ( theStr.equals( "" ) ) return FT_Undefined;
2863 else return FT_Undefined;
2866 //=======================================================================
2867 // name : toFunctorType
2868 // Purpose : Convert LDOMString to value of ElementType enumeration
2869 //=======================================================================
2870 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
2872 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
2873 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
2874 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
2875 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
2876 else return SMESH::ALL;
2879 //=======================================================================
2881 // Purpose : Convert ElementType to string
2882 //=======================================================================
2883 static inline LDOMString toString( const SMESH::ElementType theType )
2887 case SMESH::NODE : return "NODE";
2888 case SMESH::EDGE : return "EDGE";
2889 case SMESH::FACE : return "FACE";
2890 case SMESH::VOLUME : return "VOLUME";
2891 case SMESH::ALL : return "ALL";
2892 default : return "";
2896 //=======================================================================
2897 // name : findFilter
2898 // Purpose : Find filter in document
2899 //=======================================================================
2900 static LDOM_Element findFilter( const char* theFilterName,
2901 const LDOM_Document& theDoc,
2902 LDOM_Node* theParent = 0 )
2904 LDOM_Element aRootElement = theDoc.getDocumentElement();
2905 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
2906 return LDOM_Element();
2908 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
2909 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
2911 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
2912 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2914 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
2915 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
2916 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
2918 if ( theParent != 0 )
2919 *theParent = aTypeNode;
2920 return (LDOM_Element&)aFilter;
2924 return LDOM_Element();
2927 //=======================================================================
2928 // name : getSectionName
2929 // Purpose : Get name of section of filters
2930 //=======================================================================
2931 static const char* getSectionName( const ElementType theType )
2935 case SMESH::NODE : return "Filters for nodes";
2936 case SMESH::EDGE : return "Filters for edges";
2937 case SMESH::FACE : return "Filters for faces";
2938 case SMESH::VOLUME : return "Filters for volumes";
2939 case SMESH::ALL : return "Filters for elements";
2940 default : return "";
2944 //=======================================================================
2945 // name : getSection
2946 // Purpose : Create section for filters corresponding to the entity type
2947 //=======================================================================
2948 static LDOM_Node getSection( const ElementType theType,
2949 LDOM_Document& theDoc,
2950 const bool toCreate = false )
2952 LDOM_Element aRootElement = theDoc.getDocumentElement();
2953 if ( aRootElement.isNull() )
2957 bool anExist = false;
2958 const char* aSectionName = getSectionName( theType );
2959 if ( strcmp( aSectionName, "" ) == 0 )
2962 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
2964 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
2966 aNode = aSections.item( i );
2967 LDOM_Element& anItem = ( LDOM_Element& )aNode;
2968 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
2975 // Create new section if necessary
2980 LDOM_Element aNewItem = theDoc.createElement( "section" );
2981 aNewItem.setAttribute( "name", aSectionName );
2982 aRootElement.appendChild( aNewItem );
2992 //=======================================================================
2993 // name : createFilterItem
2994 // Purpose : Create filter item or LDOM document
2995 //=======================================================================
2996 static LDOM_Element createFilterItem( const char* theName,
2997 SMESH::Filter_ptr theFilter,
2998 LDOM_Document& theDoc )
3000 // create new filter in document
3001 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
3002 aFilterItem.setAttribute( "name", theName );
3004 // save filter criterions
3005 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3007 if ( !theFilter->GetCriteria( aCriteria ) )
3008 return LDOM_Element();
3010 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
3012 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
3014 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
3015 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
3016 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
3017 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
3018 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
3020 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
3021 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
3022 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
3023 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
3025 aFilterItem.appendChild( aCriterionItem );
3031 //=======================================================================
3032 // name : FilterLibrary_i::FilterLibrary_i
3033 // Purpose : Constructor
3034 //=======================================================================
3035 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
3037 myFileName = strdup( theFileName );
3038 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
3039 myFilterMgr = aFilterMgr->_this();
3043 // Try to use existing library file
3044 bool anExists = false;
3045 if ( !aParser.parse( myFileName ) )
3047 myDoc = aParser.getDocument();
3050 // Create a new XML document if it doesn't exist
3052 myDoc = LDOM_Document::createDocument( LDOMString() );
3054 LDOM_Element aRootElement = myDoc.getDocumentElement();
3055 if ( aRootElement.isNull() )
3057 // If the existing document is empty --> try to create a new one
3059 myDoc = LDOM_Document::createDocument( LDOMString() );
3063 //=======================================================================
3064 // name : FilterLibrary_i::FilterLibrary_i
3065 // Purpose : Constructor
3066 //=======================================================================
3067 FilterLibrary_i::FilterLibrary_i()
3070 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
3071 myFilterMgr = aFilter->_this();
3073 myDoc = LDOM_Document::createDocument( LDOMString() );
3076 FilterLibrary_i::~FilterLibrary_i()
3079 //TPythonDump()<<this<<".Destroy()";
3082 //=======================================================================
3083 // name : FilterLibrary_i::Copy
3084 // Purpose : Create filter and initialize it with values from library
3085 //=======================================================================
3086 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
3088 Filter_ptr aRes = Filter::_nil();
3089 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
3091 if ( aFilter.isNull() )
3094 std::list<SMESH::Filter::Criterion> aCriteria;
3096 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
3097 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
3099 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
3101 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
3102 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
3103 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
3104 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
3105 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
3107 SMESH::Filter::Criterion aCriterion = createCriterion();
3109 aCriterion.Type = toFunctorType( aTypeStr );
3110 aCriterion.Compare = toFunctorType( aCompareStr );
3111 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
3112 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
3114 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
3116 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
3118 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3119 ? val : atof( str.GetString() );
3121 str = aCrit->getAttribute( ATTR_TOLERANCE );
3122 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3123 ? val : atof( str.GetString() );
3125 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
3126 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
3129 sprintf( a, "%d", val );
3130 aCriterion.ThresholdStr = strdup( a );
3133 aCriterion.ThresholdStr = str.GetString();
3135 aCriteria.push_back( aCriterion );
3138 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
3139 aCriteriaVar->length( aCriteria.size() );
3142 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
3144 for( ; anIter != aCriteria.end(); ++anIter )
3145 aCriteriaVar[ i++ ] = *anIter;
3147 aRes = myFilterMgr->CreateFilter();
3148 aRes->SetCriteria( aCriteriaVar.inout() );
3150 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
3155 //=======================================================================
3156 // name : FilterLibrary_i::SetFileName
3157 // Purpose : Set file name for library
3158 //=======================================================================
3159 void FilterLibrary_i::SetFileName( const char* theFileName )
3162 myFileName = strdup( theFileName );
3163 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
3166 //=======================================================================
3167 // name : FilterLibrary_i::GetFileName
3168 // Purpose : Get file name of library
3169 //=======================================================================
3170 char* FilterLibrary_i::GetFileName()
3172 return CORBA::string_dup( myFileName );
3175 //=======================================================================
3176 // name : FilterLibrary_i::Add
3177 // Purpose : Add new filter to library
3178 //=======================================================================
3179 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
3181 // if filter already in library or entry filter is null do nothing
3182 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3183 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
3186 // get section corresponding to the filter type
3187 ElementType anEntType = theFilter->GetElementType();
3189 LDOM_Node aSection = getSection( anEntType, myDoc, true );
3190 if ( aSection.isNull() )
3193 // create filter item
3194 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
3195 if ( aFilterItem.isNull() )
3199 aSection.appendChild( aFilterItem );
3200 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3201 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
3206 //=======================================================================
3207 // name : FilterLibrary_i::Add
3208 // Purpose : Add new filter to library
3209 //=======================================================================
3210 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
3212 // if filter already in library or entry filter is null do nothing
3213 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3214 if ( !aFilterNode.isNull() )
3217 LDOM_Node aSection = getSection( theType, myDoc, true );
3218 if ( aSection.isNull() )
3221 // create filter item
3222 Filter_var aFilter = myFilterMgr->CreateFilter();
3224 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
3225 if ( aFilterItem.isNull() )
3229 aSection.appendChild( aFilterItem );
3230 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
3235 //=======================================================================
3236 // name : FilterLibrary_i::Delete
3237 // Purpose : Delete filter from library
3238 //=======================================================================
3239 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
3241 LDOM_Node aParentNode;
3242 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
3243 if ( aFilterNode.isNull() || aParentNode.isNull() )
3246 aParentNode.removeChild( aFilterNode );
3247 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
3251 //=======================================================================
3252 // name : FilterLibrary_i::Replace
3253 // Purpose : Replace existing filter with entry filter.
3254 // IMPORTANT : If filter does not exist it is not created
3255 //=======================================================================
3256 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
3257 const char* theNewName,
3258 Filter_ptr theFilter )
3260 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
3261 if ( aFilterItem.isNull() || theFilter->_is_nil() )
3264 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
3265 if ( aNewItem.isNull() )
3269 aFilterItem.ReplaceElement( aNewItem );
3270 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3271 TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
3276 //=======================================================================
3277 // name : FilterLibrary_i::Save
3278 // Purpose : Save library on disk
3279 //=======================================================================
3280 CORBA::Boolean FilterLibrary_i::Save()
3282 if ( myFileName == 0 || strlen( myFileName ) == 0 )
3285 FILE* aOutFile = fopen( myFileName, "wt" );
3289 LDOM_XmlWriter aWriter( aOutFile );
3290 aWriter.SetIndentation( 2 );
3294 TPythonDump()<<this<<".Save()";
3298 //=======================================================================
3299 // name : FilterLibrary_i::SaveAs
3300 // Purpose : Save library on disk
3301 //=======================================================================
3302 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
3304 myFileName = strdup ( aFileName );
3305 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
3309 //=======================================================================
3310 // name : FilterLibrary_i::IsPresent
3311 // Purpose : Verify whether filter is in library
3312 //=======================================================================
3313 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
3315 return !findFilter( theFilterName, myDoc ).isNull();
3318 //=======================================================================
3319 // name : FilterLibrary_i::NbFilters
3320 // Purpose : Return amount of filters in library
3321 //=======================================================================
3322 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
3324 string_array_var aNames = GetNames( theType );
3325 return aNames->length();
3328 //=======================================================================
3329 // name : FilterLibrary_i::GetNames
3330 // Purpose : Get names of filters from library
3331 //=======================================================================
3332 string_array* FilterLibrary_i::GetNames( ElementType theType )
3334 string_array_var anArray = new string_array;
3335 TColStd_SequenceOfHAsciiString aSeq;
3337 LDOM_Node aSection = getSection( theType, myDoc, false );
3339 if ( !aSection.isNull() )
3341 for ( LDOM_Node aFilter = aSection.getFirstChild();
3342 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3344 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
3345 aSeq.Append( new TCollection_HAsciiString(
3346 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
3350 anArray->length( aSeq.Length() );
3351 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
3352 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
3354 return anArray._retn();
3357 //=======================================================================
3358 // name : FilterLibrary_i::GetAllNames
3359 // Purpose : Get names of filters from library
3360 //=======================================================================
3361 string_array* FilterLibrary_i::GetAllNames()
3363 string_array_var aResArray = new string_array;
3364 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
3366 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
3368 int aPrevLength = aResArray->length();
3369 aResArray->length( aPrevLength + aNames->length() );
3370 for ( int i = 0, n = aNames->length(); i < n; i++ )
3371 aResArray[ aPrevLength + i ] = aNames[ i ];
3374 return aResArray._retn();