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 (dynamic_cast<SMESH::Controls::Length2D*>(myFunctorPtr.get()))->GetValues( aValues );
777 long i = 0, iEnd = aValues.size();
779 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
780 aResult->length(iEnd);
782 SMESH::Controls::Length2D::TValues::const_iterator anIter;
783 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
785 const SMESH::Controls::Length2D::Value& aVal = *anIter;
786 SMESH::Length2D::Value &aValue = aResult[ i ];
788 aValue.myLength = aVal.myLength;
789 aValue.myPnt1 = aVal.myPntId[ 0 ];
790 aValue.myPnt2 = aVal.myPntId[ 1 ];
793 INFOS("Length2D_i::GetValuess~");
794 return aResult._retn();
798 Class : MultiConnection_i
799 Description : Functor for calculating number of faces conneted to the edge
801 MultiConnection_i::MultiConnection_i()
803 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
804 myFunctorPtr = myNumericalFunctorPtr;
807 FunctorType MultiConnection_i::GetFunctorType()
809 return SMESH::FT_MultiConnection;
813 Class : MultiConnection2D_i
814 Description : Functor for calculating number of faces conneted to the edge
816 MultiConnection2D_i::MultiConnection2D_i()
818 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
819 myFunctorPtr = myNumericalFunctorPtr;
822 FunctorType MultiConnection2D_i::GetFunctorType()
824 return SMESH::FT_MultiConnection2D;
827 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
829 INFOS("MultiConnection2D_i::GetValues");
830 SMESH::Controls::MultiConnection2D::MValues aValues;
831 (dynamic_cast<SMESH::Controls::MultiConnection2D*>(myFunctorPtr.get()))->GetValues( aValues );
833 long i = 0, iEnd = aValues.size();
835 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
836 aResult->length(iEnd);
838 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
839 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
841 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
842 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
844 aValue.myPnt1 = aVal.myPntId[ 0 ];
845 aValue.myPnt2 = aVal.myPntId[ 1 ];
846 aValue.myNbConnects = (*anIter).second;
849 INFOS("Multiconnection2D_i::GetValuess~");
850 return aResult._retn();
860 Description : Base class for all predicates
862 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
864 return myPredicatePtr->IsSatisfy( theId );
867 Controls::PredicatePtr Predicate_i::GetPredicate()
869 return myPredicatePtr;
873 Class : BadOrientedVolume_i
874 Description : Verify whether a mesh volume is incorrectly oriented from
875 the point of view of MED convention
877 BadOrientedVolume_i::BadOrientedVolume_i()
879 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
880 myFunctorPtr = myPredicatePtr = control;
883 FunctorType BadOrientedVolume_i::GetFunctorType()
885 return SMESH::FT_BadOrientedVolume;
889 Class : BelongToGeom_i
890 Description : Predicate for selection on geometrical support
892 BelongToGeom_i::BelongToGeom_i()
894 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
895 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
900 BelongToGeom_i::~BelongToGeom_i()
906 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
908 if ( theGeom->_is_nil() )
910 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
911 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
912 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
913 myBelongToGeomPtr->SetGeom( aLocShape );
914 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
917 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
919 myBelongToGeomPtr->SetGeom( theShape );
922 void BelongToGeom_i::SetElementType(ElementType theType){
923 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
924 TPythonDump()<<this<<".SetElementType("<<theType<<")";
927 FunctorType BelongToGeom_i::GetFunctorType()
929 return SMESH::FT_BelongToGeom;
932 void BelongToGeom_i::SetShapeName( const char* theName )
935 myShapeName = strdup( theName );
936 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
937 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
940 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
943 myShapeName = strdup( theName );
946 myShapeID = strdup( theID );
950 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
951 myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
953 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
956 char* BelongToGeom_i::GetShapeName()
958 return CORBA::string_dup( myShapeName );
961 char* BelongToGeom_i::GetShapeID()
963 return CORBA::string_dup( myShapeID );
966 void BelongToGeom_i::SetTolerance( CORBA::Double theToler )
968 myBelongToGeomPtr->SetTolerance( theToler );
969 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
972 CORBA::Double BelongToGeom_i::GetTolerance()
974 return myBelongToGeomPtr->GetTolerance();
978 Class : BelongToSurface_i
979 Description : Predicate for selection on geometrical support
981 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
983 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
984 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
987 mySurfaceType = theSurfaceType;
990 BelongToSurface_i::~BelongToSurface_i()
996 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
998 if ( theGeom->_is_nil() )
1000 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1001 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1002 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1004 if ( aLocShape.ShapeType() == TopAbs_FACE )
1006 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
1007 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
1009 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1014 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
1017 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
1020 myShapeName = strdup( theName );
1021 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1022 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
1025 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
1028 myShapeName = strdup( theName );
1031 myShapeID = strdup( theID );
1035 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1036 myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
1038 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1041 char* BelongToSurface_i::GetShapeName()
1043 return CORBA::string_dup( myShapeName );
1046 char* BelongToSurface_i::GetShapeID()
1048 return CORBA::string_dup( myShapeID );
1051 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
1053 myElementsOnSurfacePtr->SetTolerance( theToler );
1054 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1057 CORBA::Double BelongToSurface_i::GetTolerance()
1059 return myElementsOnSurfacePtr->GetTolerance();
1062 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
1064 myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
1065 TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
1068 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
1070 return myElementsOnSurfacePtr->GetUseBoundaries();
1075 Class : BelongToPlane_i
1076 Description : Verify whether mesh element lie in pointed Geom planar object
1079 BelongToPlane_i::BelongToPlane_i()
1080 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
1084 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1086 BelongToSurface_i::SetSurface( theGeom, theType );
1087 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
1090 FunctorType BelongToPlane_i::GetFunctorType()
1092 return FT_BelongToPlane;
1096 Class : BelongToCylinder_i
1097 Description : Verify whether mesh element lie in pointed Geom planar object
1100 BelongToCylinder_i::BelongToCylinder_i()
1101 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1105 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1107 BelongToSurface_i::SetSurface( theGeom, theType );
1108 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
1111 FunctorType BelongToCylinder_i::GetFunctorType()
1113 return FT_BelongToCylinder;
1117 Class : BelongToGenSurface_i
1118 Description : Verify whether mesh element lie in pointed Geom planar object
1121 BelongToGenSurface_i::BelongToGenSurface_i()
1122 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1126 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1128 if ( theGeom->_is_nil() )
1130 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1131 if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1132 aLocShape.Nullify();
1134 BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1135 TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1138 FunctorType BelongToGenSurface_i::GetFunctorType()
1140 return FT_BelongToGenSurface;
1144 Class : LyingOnGeom_i
1145 Description : Predicate for selection on geometrical support
1147 LyingOnGeom_i::LyingOnGeom_i()
1149 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1150 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1155 LyingOnGeom_i::~LyingOnGeom_i()
1161 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1163 if ( theGeom->_is_nil() )
1165 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1166 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1167 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1168 myLyingOnGeomPtr->SetGeom( aLocShape );
1169 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1172 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1174 myLyingOnGeomPtr->SetGeom( theShape );
1177 void LyingOnGeom_i::SetElementType(ElementType theType){
1178 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1179 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1182 FunctorType LyingOnGeom_i::GetFunctorType()
1184 return SMESH::FT_LyingOnGeom;
1187 void LyingOnGeom_i::SetShapeName( const char* theName )
1190 myShapeName = strdup( theName );
1191 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1192 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1195 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1198 myShapeName = strdup( theName );
1201 myShapeID = strdup( theID );
1205 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1206 myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
1208 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1211 char* LyingOnGeom_i::GetShapeName()
1213 return CORBA::string_dup( myShapeName );
1216 char* LyingOnGeom_i::GetShapeID()
1218 return CORBA::string_dup( myShapeID );
1221 void LyingOnGeom_i::SetTolerance( CORBA::Double theToler )
1223 myLyingOnGeomPtr->SetTolerance( theToler );
1224 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1227 CORBA::Double LyingOnGeom_i::GetTolerance()
1229 return myLyingOnGeomPtr->GetTolerance();
1233 Class : FreeBorders_i
1234 Description : Predicate for free borders
1236 FreeBorders_i::FreeBorders_i()
1238 myPredicatePtr.reset(new Controls::FreeBorders());
1239 myFunctorPtr = myPredicatePtr;
1242 FunctorType FreeBorders_i::GetFunctorType()
1244 return SMESH::FT_FreeBorders;
1249 Description : Predicate for free borders
1251 FreeEdges_i::FreeEdges_i()
1252 : myFreeEdgesPtr( new Controls::FreeEdges() )
1254 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1257 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1259 INFOS("FreeEdges_i::GetBorders");
1260 SMESH::Controls::FreeEdges::TBorders aBorders;
1261 myFreeEdgesPtr->GetBoreders( aBorders );
1263 long i = 0, iEnd = aBorders.size();
1265 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1266 aResult->length(iEnd);
1268 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1269 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1271 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1272 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1274 aBorder.myElemId = aBord.myElemId;
1275 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1276 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1279 INFOS("FreeEdges_i::GetBorders~");
1280 return aResult._retn();
1283 FunctorType FreeEdges_i::GetFunctorType()
1285 return SMESH::FT_FreeEdges;
1290 Description : Predicate for free faces
1292 FreeFaces_i::FreeFaces_i()
1294 myPredicatePtr.reset(new Controls::FreeFaces());
1295 myFunctorPtr = myPredicatePtr;
1298 FunctorType FreeFaces_i::GetFunctorType()
1300 return SMESH::FT_FreeFaces;
1305 Description : Predicate for free nodes
1307 FreeNodes_i::FreeNodes_i()
1309 myPredicatePtr.reset(new Controls::FreeNodes());
1310 myFunctorPtr = myPredicatePtr;
1313 FunctorType FreeNodes_i::GetFunctorType()
1315 return SMESH::FT_FreeNodes;
1319 Class : RangeOfIds_i
1320 Description : Predicate for Range of Ids.
1321 Range may be specified with two ways.
1322 1. Using AddToRange method
1323 2. With SetRangeStr method. Parameter of this method is a string
1324 like as "1,2,3,50-60,63,67,70-"
1327 RangeOfIds_i::RangeOfIds_i()
1329 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1330 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1333 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1335 CORBA::Long iEnd = theIds.length();
1336 for ( CORBA::Long i = 0; i < iEnd; i++ )
1337 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1338 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1341 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1343 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1344 return myRangeOfIdsPtr->SetRangeStr(
1345 TCollection_AsciiString( (Standard_CString)theRange ) );
1348 char* RangeOfIds_i::GetRangeStr()
1350 TCollection_AsciiString aStr;
1351 myRangeOfIdsPtr->GetRangeStr( aStr );
1352 return CORBA::string_dup( aStr.ToCString() );
1355 void RangeOfIds_i::SetElementType( ElementType theType )
1357 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1358 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1361 FunctorType RangeOfIds_i::GetFunctorType()
1363 return SMESH::FT_RangeOfIds;
1367 Class : LinearOrQuadratic_i
1368 Description : Predicate to verify whether a mesh element is linear
1370 LinearOrQuadratic_i::LinearOrQuadratic_i()
1372 myLinearOrQuadraticPtr.reset(new Controls::LinearOrQuadratic());
1373 myFunctorPtr = myPredicatePtr = myLinearOrQuadraticPtr;
1376 void LinearOrQuadratic_i::SetElementType(ElementType theType)
1378 myLinearOrQuadraticPtr->SetType(SMDSAbs_ElementType(theType));
1379 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1382 FunctorType LinearOrQuadratic_i::GetFunctorType()
1384 return SMESH::FT_LinearOrQuadratic;
1388 Class : GroupColor_i
1389 Description : Functor for check color of group to whic mesh element belongs to
1391 GroupColor_i::GroupColor_i()
1393 myGroupColorPtr.reset(new Controls::GroupColor());
1394 myFunctorPtr = myPredicatePtr = myGroupColorPtr;
1397 FunctorType GroupColor_i::GetFunctorType()
1399 return SMESH::FT_GroupColor;
1402 void GroupColor_i::SetColorStr( const char* theColor )
1404 myGroupColorPtr->SetColorStr(
1405 TCollection_AsciiString( (Standard_CString)theColor ) );
1406 TPythonDump()<<this<<".SetColorStr('"<<theColor<<"')";
1409 char* GroupColor_i::GetColorStr()
1411 TCollection_AsciiString aStr;
1412 myGroupColorPtr->GetColorStr( aStr );
1413 return CORBA::string_dup( aStr.ToCString() );
1416 void GroupColor_i::SetElementType(ElementType theType)
1418 myGroupColorPtr->SetType(SMDSAbs_ElementType(theType));
1419 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1423 Class : ElemGeomType_i
1424 Description : Predicate check is element has indicated geometry type
1426 ElemGeomType_i::ElemGeomType_i()
1428 myElemGeomTypePtr.reset(new Controls::ElemGeomType());
1429 myFunctorPtr = myPredicatePtr = myElemGeomTypePtr;
1432 void ElemGeomType_i::SetElementType(ElementType theType)
1434 myElemGeomTypePtr->SetType(SMDSAbs_ElementType(theType));
1435 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1438 void ElemGeomType_i::SetGeometryType(GeometryType theType)
1440 myElemGeomTypePtr->SetGeomType(SMDSAbs_GeometryType(theType));
1441 TPythonDump()<<this<<".SetGeometryType("<<theType<<")";
1444 GeometryType ElemGeomType_i::GetGeometryType() const
1446 return (GeometryType)myElemGeomTypePtr->GetGeomType();;
1449 FunctorType ElemGeomType_i::GetFunctorType()
1451 return SMESH::FT_ElemGeomType;
1455 Class : Comparator_i
1456 Description : Base class for comparators
1458 Comparator_i::Comparator_i():
1459 myNumericalFunctor( NULL )
1462 Comparator_i::~Comparator_i()
1464 if ( myNumericalFunctor )
1465 myNumericalFunctor->Destroy();
1468 void Comparator_i::SetMargin( CORBA::Double theValue )
1470 myComparatorPtr->SetMargin( theValue );
1471 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1474 CORBA::Double Comparator_i::GetMargin()
1476 return myComparatorPtr->GetMargin();
1479 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1481 if ( myNumericalFunctor )
1482 myNumericalFunctor->Destroy();
1484 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1486 if ( myNumericalFunctor )
1488 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1489 myNumericalFunctor->Register();
1490 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1494 Controls::ComparatorPtr Comparator_i::GetComparator()
1496 return myComparatorPtr;
1499 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1501 return myNumericalFunctor;
1507 Description : Comparator "<"
1509 LessThan_i::LessThan_i()
1511 myComparatorPtr.reset( new Controls::LessThan() );
1512 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1515 FunctorType LessThan_i::GetFunctorType()
1517 return SMESH::FT_LessThan;
1523 Description : Comparator ">"
1525 MoreThan_i::MoreThan_i()
1527 myComparatorPtr.reset( new Controls::MoreThan() );
1528 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1531 FunctorType MoreThan_i::GetFunctorType()
1533 return SMESH::FT_MoreThan;
1539 Description : Comparator "="
1541 EqualTo_i::EqualTo_i()
1542 : myEqualToPtr( new Controls::EqualTo() )
1544 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1547 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1549 myEqualToPtr->SetTolerance( theToler );
1550 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1553 CORBA::Double EqualTo_i::GetTolerance()
1555 return myEqualToPtr->GetTolerance();
1558 FunctorType EqualTo_i::GetFunctorType()
1560 return SMESH::FT_EqualTo;
1564 Class : LogicalNOT_i
1565 Description : Logical NOT predicate
1567 LogicalNOT_i::LogicalNOT_i()
1568 : myPredicate( NULL ),
1569 myLogicalNOTPtr( new Controls::LogicalNOT() )
1571 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1574 LogicalNOT_i::~LogicalNOT_i()
1577 myPredicate->Destroy();
1580 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1583 myPredicate->Destroy();
1585 myPredicate = SMESH::GetPredicate(thePredicate);
1588 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1589 myPredicate->Register();
1590 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1594 FunctorType LogicalNOT_i::GetFunctorType()
1596 return SMESH::FT_LogicalNOT;
1599 Predicate_i* LogicalNOT_i::GetPredicate_i()
1606 Class : LogicalBinary_i
1607 Description : Base class for binary logical predicate
1609 LogicalBinary_i::LogicalBinary_i()
1610 : myPredicate1( NULL ),
1611 myPredicate2( NULL )
1614 LogicalBinary_i::~LogicalBinary_i()
1617 myPredicate1->Destroy();
1620 myPredicate2->Destroy();
1623 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1626 myPredicate1->SetMesh( theMesh );
1629 myPredicate2->SetMesh( theMesh );
1632 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1635 myPredicate1->Destroy();
1637 myPredicate1 = SMESH::GetPredicate(thePredicate);
1639 if ( myPredicate1 ){
1640 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1641 myPredicate1->Register();
1642 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1646 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1649 myPredicate2->Destroy();
1651 myPredicate2 = SMESH::GetPredicate(thePredicate);
1653 if ( myPredicate2 ){
1654 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1655 myPredicate2->Register();
1656 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1660 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1662 return myLogicalBinaryPtr;
1665 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1667 return myPredicate1;
1669 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1671 return myPredicate2;
1676 Class : LogicalAND_i
1677 Description : Logical AND
1679 LogicalAND_i::LogicalAND_i()
1681 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1682 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1685 FunctorType LogicalAND_i::GetFunctorType()
1687 return SMESH::FT_LogicalAND;
1693 Description : Logical OR
1695 LogicalOR_i::LogicalOR_i()
1697 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1698 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1701 FunctorType LogicalOR_i::GetFunctorType()
1703 return SMESH::FT_LogicalOR;
1711 FilterManager_i::FilterManager_i()
1712 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1714 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
1715 //PortableServer::ObjectId_var anObjectId =
1716 // SMESH_Gen_i::GetPOA()->activate_object( this );
1720 FilterManager_i::~FilterManager_i()
1722 //TPythonDump()<<this<<".Destroy()";
1726 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1728 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1729 SMESH::MinimumAngle_var anObj = aServant->_this();
1730 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1731 return anObj._retn();
1735 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1737 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1738 SMESH::AspectRatio_var anObj = aServant->_this();
1739 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1740 return anObj._retn();
1744 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1746 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1747 SMESH::AspectRatio3D_var anObj = aServant->_this();
1748 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1749 return anObj._retn();
1753 Warping_ptr FilterManager_i::CreateWarping()
1755 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1756 SMESH::Warping_var anObj = aServant->_this();
1757 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1758 return anObj._retn();
1762 Taper_ptr FilterManager_i::CreateTaper()
1764 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1765 SMESH::Taper_var anObj = aServant->_this();
1766 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1767 return anObj._retn();
1771 Skew_ptr FilterManager_i::CreateSkew()
1773 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1774 SMESH::Skew_var anObj = aServant->_this();
1775 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1776 return anObj._retn();
1780 Area_ptr FilterManager_i::CreateArea()
1782 SMESH::Area_i* aServant = new SMESH::Area_i();
1783 SMESH::Area_var anObj = aServant->_this();
1784 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1785 return anObj._retn();
1789 Volume3D_ptr FilterManager_i::CreateVolume3D()
1791 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
1792 SMESH::Volume3D_var anObj = aServant->_this();
1793 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
1794 return anObj._retn();
1798 Length_ptr FilterManager_i::CreateLength()
1800 SMESH::Length_i* aServant = new SMESH::Length_i();
1801 SMESH::Length_var anObj = aServant->_this();
1802 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1803 return anObj._retn();
1806 Length2D_ptr FilterManager_i::CreateLength2D()
1808 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1809 SMESH::Length2D_var anObj = aServant->_this();
1810 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1811 return anObj._retn();
1814 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1816 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1817 SMESH::MultiConnection_var anObj = aServant->_this();
1818 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1819 return anObj._retn();
1822 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1824 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1825 SMESH::MultiConnection2D_var anObj = aServant->_this();
1826 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
1827 return anObj._retn();
1830 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1832 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1833 SMESH::BelongToGeom_var anObj = aServant->_this();
1834 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
1835 return anObj._retn();
1838 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1840 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1841 SMESH::BelongToPlane_var anObj = aServant->_this();
1842 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
1843 return anObj._retn();
1846 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1848 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1849 SMESH::BelongToCylinder_var anObj = aServant->_this();
1850 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
1851 return anObj._retn();
1854 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
1856 SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
1857 SMESH::BelongToGenSurface_var anObj = aServant->_this();
1858 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
1859 return anObj._retn();
1862 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
1864 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
1865 SMESH::LyingOnGeom_var anObj = aServant->_this();
1866 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
1867 return anObj._retn();
1870 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1872 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1873 SMESH::FreeBorders_var anObj = aServant->_this();
1874 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
1875 return anObj._retn();
1878 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1880 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1881 SMESH::FreeEdges_var anObj = aServant->_this();
1882 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
1883 return anObj._retn();
1886 FreeFaces_ptr FilterManager_i::CreateFreeFaces()
1888 SMESH::FreeFaces_i* aServant = new SMESH::FreeFaces_i();
1889 SMESH::FreeFaces_var anObj = aServant->_this();
1890 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeFaces()";
1891 return anObj._retn();
1894 FreeNodes_ptr FilterManager_i::CreateFreeNodes()
1896 SMESH::FreeNodes_i* aServant = new SMESH::FreeNodes_i();
1897 SMESH::FreeNodes_var anObj = aServant->_this();
1898 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeNodes()";
1899 return anObj._retn();
1902 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1904 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1905 SMESH::RangeOfIds_var anObj = aServant->_this();
1906 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
1907 return anObj._retn();
1910 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
1912 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
1913 SMESH::BadOrientedVolume_var anObj = aServant->_this();
1914 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
1915 return anObj._retn();
1918 LessThan_ptr FilterManager_i::CreateLessThan()
1920 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1921 SMESH::LessThan_var anObj = aServant->_this();
1922 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
1923 return anObj._retn();
1926 MoreThan_ptr FilterManager_i::CreateMoreThan()
1928 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1929 SMESH::MoreThan_var anObj = aServant->_this();
1930 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
1931 return anObj._retn();
1934 EqualTo_ptr FilterManager_i::CreateEqualTo()
1936 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1937 SMESH::EqualTo_var anObj = aServant->_this();
1938 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
1939 return anObj._retn();
1942 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1944 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1945 SMESH::LogicalNOT_var anObj = aServant->_this();
1946 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
1947 return anObj._retn();
1950 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
1952 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
1953 SMESH::LogicalAND_var anObj = aServant->_this();
1954 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
1955 return anObj._retn();
1958 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
1960 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
1961 SMESH::LogicalOR_var anObj = aServant->_this();
1962 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
1963 return anObj._retn();
1966 LinearOrQuadratic_ptr FilterManager_i::CreateLinearOrQuadratic()
1968 SMESH::LinearOrQuadratic_i* aServant = new SMESH::LinearOrQuadratic_i();
1969 SMESH::LinearOrQuadratic_var anObj = aServant->_this();
1970 TPythonDump()<<aServant<<" = "<<this<<".CreateLinearOrQuadratic()";
1971 return anObj._retn();
1974 GroupColor_ptr FilterManager_i::CreateGroupColor()
1976 SMESH::GroupColor_i* aServant = new SMESH::GroupColor_i();
1977 SMESH::GroupColor_var anObj = aServant->_this();
1978 TPythonDump()<<aServant<<" = "<<this<<".CreateGroupColor()";
1979 return anObj._retn();
1982 ElemGeomType_ptr FilterManager_i::CreateElemGeomType()
1984 SMESH::ElemGeomType_i* aServant = new SMESH::ElemGeomType_i();
1985 SMESH::ElemGeomType_var anObj = aServant->_this();
1986 TPythonDump()<<aServant<<" = "<<this<<".CreateElemGeomType()";
1987 return anObj._retn();
1990 Filter_ptr FilterManager_i::CreateFilter()
1992 SMESH::Filter_i* aServant = new SMESH::Filter_i();
1993 SMESH::Filter_var anObj = aServant->_this();
1994 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
1995 return anObj._retn();
1998 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
2000 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
2001 SMESH::FilterLibrary_var anObj = aServant->_this();
2002 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary('"<<aFileName<<"')";
2003 return anObj._retn();
2006 FilterLibrary_ptr FilterManager_i::CreateLibrary()
2008 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
2009 SMESH::FilterLibrary_var anObj = aServant->_this();
2010 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
2011 return anObj._retn();
2014 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
2016 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
2017 return remove( aFileName ) ? false : true;
2020 //=============================================================================
2022 * SMESH_Gen_i::CreateFilterManager
2024 * Create filter manager
2026 //=============================================================================
2028 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
2030 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2031 SMESH::FilterManager_var anObj = aFilter->_this();
2032 return anObj._retn();
2040 //=======================================================================
2041 // name : Filter_i::Filter_i
2042 // Purpose : Constructor
2043 //=======================================================================
2044 Filter_i::Filter_i()
2045 : myPredicate( NULL )
2048 //=======================================================================
2049 // name : Filter_i::~Filter_i
2050 // Purpose : Destructor
2051 //=======================================================================
2052 Filter_i::~Filter_i()
2055 myPredicate->Destroy();
2057 if(!CORBA::is_nil(myMesh))
2060 //TPythonDump()<<this<<".Destroy()";
2063 //=======================================================================
2064 // name : Filter_i::SetPredicate
2065 // Purpose : Set predicate
2066 //=======================================================================
2067 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
2070 myPredicate->Destroy();
2072 myPredicate = SMESH::GetPredicate(thePredicate);
2076 myFilter.SetPredicate( myPredicate->GetPredicate() );
2077 myPredicate->Register();
2078 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
2082 //=======================================================================
2083 // name : Filter_i::GetElementType
2084 // Purpose : Get entity type
2085 //=======================================================================
2086 SMESH::ElementType Filter_i::GetElementType()
2088 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
2091 //=======================================================================
2092 // name : Filter_i::SetMesh
2093 // Purpose : Set mesh
2094 //=======================================================================
2097 SetMesh( SMESH_Mesh_ptr theMesh )
2099 if(!CORBA::is_nil(theMesh))
2100 theMesh->Register();
2102 if(!CORBA::is_nil(myMesh))
2105 myMesh = SMESH_Mesh::_duplicate( theMesh );
2106 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
2113 return GetElementsId(myMesh);
2116 //=======================================================================
2117 // name : Filter_i::GetElementsId
2118 // Purpose : Get ids of entities
2119 //=======================================================================
2122 GetElementsId( Predicate_i* thePredicate,
2123 const SMDS_Mesh* theMesh,
2124 Controls::Filter::TIdSequence& theSequence )
2127 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
2132 GetElementsId( Predicate_i* thePredicate,
2133 SMESH_Mesh_ptr theMesh,
2134 Controls::Filter::TIdSequence& theSequence )
2137 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2138 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
2143 GetElementsId( SMESH_Mesh_ptr theMesh )
2145 SMESH::long_array_var anArray = new SMESH::long_array;
2146 if(!CORBA::is_nil(theMesh) && myPredicate){
2147 Controls::Filter::TIdSequence aSequence;
2148 GetElementsId(myPredicate,theMesh,aSequence);
2149 long i = 0, iEnd = aSequence.size();
2150 anArray->length( iEnd );
2151 for ( ; i < iEnd; i++ )
2152 anArray[ i ] = aSequence[i];
2154 return anArray._retn();
2157 template<class TElement, class TIterator, class TPredicate>
2158 static void collectMeshInfo(const TIterator& theItr,
2159 TPredicate& thePred,
2160 SMESH::long_array& theRes)
2164 while (theItr->more()) {
2165 const SMDS_MeshElement* anElem = theItr->next();
2166 if ( thePred->IsSatisfy( anElem->GetID() ) )
2167 theRes[ anElem->GetEntityType() ]++;
2171 //=============================================================================
2173 * \brief Returns statistic of mesh elements
2175 //=============================================================================
2176 SMESH::long_array* ::Filter_i::GetMeshInfo()
2178 SMESH::long_array_var aRes = new SMESH::long_array();
2179 aRes->length(SMESH::Entity_Last);
2180 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
2183 if(!CORBA::is_nil(myMesh) && myPredicate) {
2184 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2185 SMDS_ElemIteratorPtr it;
2186 switch( GetElementType() )
2189 collectMeshInfo<const SMDS_MeshNode*>(aMesh->nodesIterator(),myPredicate,aRes);
2192 collectMeshInfo<const SMDS_MeshElement*>(aMesh->edgesIterator(),myPredicate,aRes);
2195 collectMeshInfo<const SMDS_MeshElement*>(aMesh->facesIterator(),myPredicate,aRes);
2197 case SMDSAbs_Volume:
2198 collectMeshInfo<const SMDS_MeshElement*>(aMesh->volumesIterator(),myPredicate,aRes);
2202 collectMeshInfo<const SMDS_MeshElement*>(aMesh->elementsIterator(),myPredicate,aRes);
2208 return aRes._retn();
2211 //================================================================================
2213 * \brief Return GetElementType() within an array
2214 * Implement SMESH_IDSource interface
2216 //================================================================================
2218 SMESH::array_of_ElementType* Filter_i::GetTypes()
2220 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
2222 types[0] = GetElementType();
2223 return types._retn();
2226 //=======================================================================
2227 // name : getCriteria
2228 // Purpose : Retrieve criterions from predicate
2229 //=======================================================================
2230 static inline bool getCriteria( Predicate_i* thePred,
2231 SMESH::Filter::Criteria_out theCriteria )
2233 int aFType = thePred->GetFunctorType();
2237 case FT_FreeBorders:
2240 case FT_LinearOrQuadratic:
2243 CORBA::ULong i = theCriteria->length();
2244 theCriteria->length( i + 1 );
2246 theCriteria[ i ] = createCriterion();
2248 theCriteria[ i ].Type = aFType;
2249 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
2252 case FT_BelongToGeom:
2254 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
2256 CORBA::ULong i = theCriteria->length();
2257 theCriteria->length( i + 1 );
2259 theCriteria[ i ] = createCriterion();
2261 theCriteria[ i ].Type = FT_BelongToGeom;
2262 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2263 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2264 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2265 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2269 case FT_BelongToPlane:
2270 case FT_BelongToCylinder:
2271 case FT_BelongToGenSurface:
2273 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
2275 CORBA::ULong i = theCriteria->length();
2276 theCriteria->length( i + 1 );
2278 theCriteria[ i ] = createCriterion();
2280 theCriteria[ i ].Type = aFType;
2281 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2282 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2283 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2284 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2288 case FT_LyingOnGeom:
2290 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
2292 CORBA::ULong i = theCriteria->length();
2293 theCriteria->length( i + 1 );
2295 theCriteria[ i ] = createCriterion();
2297 theCriteria[ i ].Type = FT_LyingOnGeom;
2298 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2299 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2300 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2301 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2307 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
2309 CORBA::ULong i = theCriteria->length();
2310 theCriteria->length( i + 1 );
2312 theCriteria[ i ] = createCriterion();
2314 theCriteria[ i ].Type = FT_RangeOfIds;
2315 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
2316 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2320 case FT_BadOrientedVolume:
2322 BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
2324 CORBA::ULong i = theCriteria->length();
2325 theCriteria->length( i + 1 );
2327 theCriteria[ i ] = createCriterion();
2329 theCriteria[ i ].Type = FT_BadOrientedVolume;
2330 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2338 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
2340 CORBA::ULong i = theCriteria->length();
2341 theCriteria->length( i + 1 );
2343 theCriteria[ i ] = createCriterion();
2345 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
2346 theCriteria[ i ].Compare = aFType;
2347 theCriteria[ i ].Threshold = aCompar->GetMargin();
2348 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
2350 if ( aFType == FT_EqualTo )
2352 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
2353 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
2360 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2361 getCriteria( aPred, theCriteria );
2362 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2369 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2370 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2371 if ( !getCriteria( aPred1, theCriteria ) )
2373 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2374 return getCriteria( aPred2, theCriteria );
2378 CORBA::ULong i = theCriteria->length();
2379 theCriteria->length( i + 1 );
2381 theCriteria[ i ] = createCriterion();
2383 GroupColor_i* aPred = dynamic_cast<GroupColor_i*>( thePred );
2384 theCriteria[ i ].Type = aFType;
2385 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2386 theCriteria[ i ].ThresholdStr = aPred->GetColorStr();
2390 case FT_ElemGeomType:
2392 CORBA::ULong i = theCriteria->length();
2393 theCriteria->length( i + 1 );
2395 theCriteria[ i ] = createCriterion();
2397 ElemGeomType_i* aPred = dynamic_cast<ElemGeomType_i*>( thePred );
2398 theCriteria[ i ].Type = aFType;
2399 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2400 theCriteria[ i ].Threshold = (double)aPred->GetGeometryType();
2411 //=======================================================================
2412 // name : Filter_i::GetCriteria
2413 // Purpose : Retrieve criterions from predicate
2414 //=======================================================================
2415 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2417 theCriteria = new SMESH::Filter::Criteria;
2418 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2421 //=======================================================================
2422 // name : Filter_i::SetCriteria
2423 // Purpose : Create new predicate and set criterions in it
2424 //=======================================================================
2425 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2427 if ( myPredicate != 0 )
2428 myPredicate->Destroy();
2430 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2431 FilterManager_ptr aFilterMgr = aFilter->_this();
2433 // CREATE two lists ( PREDICATES and LOG OP )
2436 TPythonDump()<<"aCriteria = []";
2437 std::list<SMESH::Predicate_ptr> aPredicates;
2438 std::list<int> aBinaries;
2439 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2441 int aCriterion = theCriteria[ i ].Type;
2442 int aCompare = theCriteria[ i ].Compare;
2443 double aThreshold = theCriteria[ i ].Threshold;
2444 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2445 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2446 int aUnary = theCriteria[ i ].UnaryOp;
2447 int aBinary = theCriteria[ i ].BinaryOp;
2448 double aTolerance = theCriteria[ i ].Tolerance;
2449 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
2450 long aPrecision = theCriteria[ i ].Precision;
2454 pd << "aCriterion = SMESH.Filter.Criterion(" << aCriterion << "," << aCompare
2455 << "," << aThreshold << ",'" << aThresholdStr;
2456 if (aThresholdID && strlen(aThresholdID))
2457 //pd << "',salome.ObjectToID(" << aThresholdID
2458 pd << "','" << aThresholdID
2459 << "'," << aUnary << "," << aBinary << "," << aTolerance
2460 << "," << aTypeOfElem << "," << aPrecision << ")";
2462 pd << "',''," << aUnary << "," << aBinary << "," << aTolerance
2463 << "," << aTypeOfElem << "," << aPrecision << ")";
2466 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2467 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2469 switch ( aCriterion )
2473 case SMESH::FT_MultiConnection:
2474 aFunctor = aFilterMgr->CreateMultiConnection();
2476 case SMESH::FT_MultiConnection2D:
2477 aFunctor = aFilterMgr->CreateMultiConnection2D();
2479 case SMESH::FT_Length:
2480 aFunctor = aFilterMgr->CreateLength();
2482 case SMESH::FT_Length2D:
2483 aFunctor = aFilterMgr->CreateLength2D();
2485 case SMESH::FT_AspectRatio:
2486 aFunctor = aFilterMgr->CreateAspectRatio();
2488 case SMESH::FT_AspectRatio3D:
2489 aFunctor = aFilterMgr->CreateAspectRatio3D();
2491 case SMESH::FT_Warping:
2492 aFunctor = aFilterMgr->CreateWarping();
2494 case SMESH::FT_MinimumAngle:
2495 aFunctor = aFilterMgr->CreateMinimumAngle();
2497 case SMESH::FT_Taper:
2498 aFunctor = aFilterMgr->CreateTaper();
2500 case SMESH::FT_Skew:
2501 aFunctor = aFilterMgr->CreateSkew();
2503 case SMESH::FT_Area:
2504 aFunctor = aFilterMgr->CreateArea();
2506 case SMESH::FT_Volume3D:
2507 aFunctor = aFilterMgr->CreateVolume3D();
2512 case SMESH::FT_FreeBorders:
2513 aPredicate = aFilterMgr->CreateFreeBorders();
2515 case SMESH::FT_FreeEdges:
2516 aPredicate = aFilterMgr->CreateFreeEdges();
2518 case SMESH::FT_FreeFaces:
2519 aPredicate = aFilterMgr->CreateFreeFaces();
2521 case SMESH::FT_FreeNodes:
2522 aPredicate = aFilterMgr->CreateFreeNodes();
2524 case SMESH::FT_BelongToGeom:
2526 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2527 tmpPred->SetElementType( aTypeOfElem );
2528 tmpPred->SetShape( aThresholdID, aThresholdStr );
2529 tmpPred->SetTolerance( aTolerance );
2530 aPredicate = tmpPred;
2533 case SMESH::FT_BelongToPlane:
2534 case SMESH::FT_BelongToCylinder:
2535 case SMESH::FT_BelongToGenSurface:
2537 SMESH::BelongToSurface_ptr tmpPred;
2538 switch ( aCriterion ) {
2539 case SMESH::FT_BelongToPlane:
2540 tmpPred = aFilterMgr->CreateBelongToPlane(); break;
2541 case SMESH::FT_BelongToCylinder:
2542 tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
2544 tmpPred = aFilterMgr->CreateBelongToGenSurface();
2546 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2547 tmpPred->SetTolerance( aTolerance );
2548 aPredicate = tmpPred;
2551 case SMESH::FT_LyingOnGeom:
2553 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2554 tmpPred->SetElementType( aTypeOfElem );
2555 tmpPred->SetShape( aThresholdID, aThresholdStr );
2556 tmpPred->SetTolerance( aTolerance );
2557 aPredicate = tmpPred;
2560 case SMESH::FT_RangeOfIds:
2562 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2563 tmpPred->SetRangeStr( aThresholdStr );
2564 tmpPred->SetElementType( aTypeOfElem );
2565 aPredicate = tmpPred;
2568 case SMESH::FT_BadOrientedVolume:
2570 aPredicate = aFilterMgr->CreateBadOrientedVolume();
2573 case SMESH::FT_LinearOrQuadratic:
2575 SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
2576 tmpPred->SetElementType( aTypeOfElem );
2577 aPredicate = tmpPred;
2580 case SMESH::FT_GroupColor:
2582 SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor();
2583 tmpPred->SetElementType( aTypeOfElem );
2584 tmpPred->SetColorStr( aThresholdStr );
2585 aPredicate = tmpPred;
2588 case SMESH::FT_ElemGeomType:
2590 SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType();
2591 tmpPred->SetElementType( aTypeOfElem );
2592 tmpPred->SetGeometryType( (GeometryType)(int)(aThreshold + 0.5) );
2593 aPredicate = tmpPred;
2602 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
2604 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
2606 if ( aCompare == SMESH::FT_LessThan )
2607 aComparator = aFilterMgr->CreateLessThan();
2608 else if ( aCompare == SMESH::FT_MoreThan )
2609 aComparator = aFilterMgr->CreateMoreThan();
2610 else if ( aCompare == SMESH::FT_EqualTo )
2611 aComparator = aFilterMgr->CreateEqualTo();
2615 aComparator->SetNumFunctor( aFunctor );
2616 aComparator->SetMargin( aThreshold );
2618 if ( aCompare == FT_EqualTo )
2620 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
2621 anEqualTo->SetTolerance( aTolerance );
2624 aPredicate = aComparator;
2626 aFunctor->SetPrecision( aPrecision );
2630 if ( aUnary == FT_LogicalNOT )
2632 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
2633 aNotPred->SetPredicate( aPredicate );
2634 aPredicate = aNotPred;
2638 aPredicates.push_back( aPredicate );
2639 aBinaries.push_back( aBinary );
2640 TPythonDump()<<"aCriteria.append(aCriterion)";
2643 TPythonDump()<<this<<".SetCriteria(aCriteria)";
2645 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
2647 // combine all "AND" operations
2649 std::list<SMESH::Predicate_ptr> aResList;
2651 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
2652 std::list<int>::iterator aBinaryIter;
2654 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
2655 int aPrevBinary = SMESH::FT_Undefined;
2657 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
2658 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
2659 ++aPredIter, ++aBinaryIter )
2661 int aCurrBinary = *aBinaryIter;
2663 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
2665 if ( aPrevBinary == SMESH::FT_LogicalAND )
2668 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2669 aBinaryPred->SetPredicate1( aPrevPredicate );
2670 aBinaryPred->SetPredicate2( *aPredIter );
2671 aCurrPred = aBinaryPred;
2674 aCurrPred = *aPredIter;
2676 if ( aCurrBinary != SMESH::FT_LogicalAND )
2677 aResList.push_back( aCurrPred );
2679 aPrevPredicate = aCurrPred;
2680 aPrevBinary = aCurrBinary;
2683 // combine all "OR" operations
2685 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2687 if ( aResList.size() == 1 )
2688 aResPredicate = *aResList.begin();
2689 else if ( aResList.size() > 1 )
2691 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2692 aResPredicate = *anIter;
2694 for ( ; anIter != aResList.end(); ++anIter )
2696 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2697 aBinaryPred->SetPredicate1( aResPredicate );
2698 aBinaryPred->SetPredicate2( *anIter );
2699 aResPredicate = aBinaryPred;
2703 SetPredicate( aResPredicate );
2705 return !aResPredicate->_is_nil();
2708 //=======================================================================
2709 // name : Filter_i::GetPredicate_i
2710 // Purpose : Get implementation of predicate
2711 //=======================================================================
2712 Predicate_i* Filter_i::GetPredicate_i()
2717 //=======================================================================
2718 // name : Filter_i::GetPredicate
2719 // Purpose : Get predicate
2720 //=======================================================================
2721 Predicate_ptr Filter_i::GetPredicate()
2723 if ( myPredicate == 0 )
2724 return SMESH::Predicate::_nil();
2727 SMESH::Predicate_var anObj = myPredicate->_this();
2728 return anObj._retn();
2736 #define ATTR_TYPE "type"
2737 #define ATTR_COMPARE "compare"
2738 #define ATTR_THRESHOLD "threshold"
2739 #define ATTR_UNARY "unary"
2740 #define ATTR_BINARY "binary"
2741 #define ATTR_THRESHOLD_STR "threshold_str"
2742 #define ATTR_TOLERANCE "tolerance"
2743 #define ATTR_ELEMENT_TYPE "ElementType"
2745 //=======================================================================
2747 // Purpose : Convert bool to LDOMString
2748 //=======================================================================
2749 static inline LDOMString toString( CORBA::Boolean val )
2751 return val ? "logical not" : "";
2754 //=======================================================================
2756 // Purpose : Convert LDOMString to bool
2757 //=======================================================================
2758 static inline bool toBool( const LDOMString& theStr )
2760 return theStr.equals( "logical not" );
2763 //=======================================================================
2765 // Purpose : Convert double to LDOMString
2766 //=======================================================================
2767 static inline LDOMString toString( CORBA::Double val )
2770 sprintf( a, "%e", val );
2771 return LDOMString( a );
2774 //=======================================================================
2776 // Purpose : Convert LDOMString to double
2777 //=======================================================================
2778 static inline double toDouble( const LDOMString& theStr )
2780 return atof( theStr.GetString() );
2783 //=======================================================================
2785 // Purpose : Convert functor type to LDOMString
2786 //=======================================================================
2787 static inline LDOMString toString( CORBA::Long theType )
2791 case FT_AspectRatio : return "Aspect ratio";
2792 case FT_Warping : return "Warping";
2793 case FT_MinimumAngle : return "Minimum angle";
2794 case FT_Taper : return "Taper";
2795 case FT_Skew : return "Skew";
2796 case FT_Area : return "Area";
2797 case FT_Volume3D : return "Volume3D";
2798 case FT_BelongToGeom : return "Belong to Geom";
2799 case FT_BelongToPlane : return "Belong to Plane";
2800 case FT_BelongToCylinder: return "Belong to Cylinder";
2801 case FT_BelongToGenSurface: return "Belong to Generic Surface";
2802 case FT_LyingOnGeom : return "Lying on Geom";
2803 case FT_BadOrientedVolume: return "Bad Oriented Volume";
2804 case FT_RangeOfIds : return "Range of IDs";
2805 case FT_FreeBorders : return "Free borders";
2806 case FT_FreeEdges : return "Free edges";
2807 case FT_FreeFaces : return "Free faces";
2808 case FT_FreeNodes : return "Free nodes";
2809 case FT_MultiConnection : return "Borders at multi-connections";
2810 case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2811 case FT_Length : return "Length";
2812 case FT_Length2D : return "Length 2D";
2813 case FT_LessThan : return "Less than";
2814 case FT_MoreThan : return "More than";
2815 case FT_EqualTo : return "Equal to";
2816 case FT_LogicalNOT : return "Not";
2817 case FT_LogicalAND : return "And";
2818 case FT_LogicalOR : return "Or";
2819 case FT_GroupColor : return "Color of Group";
2820 case FT_LinearOrQuadratic : return "Linear or Quadratic";
2821 case FT_ElemGeomType : return "Element geomtry type";
2822 case FT_Undefined : return "";
2823 default : return "";
2827 //=======================================================================
2828 // name : toFunctorType
2829 // Purpose : Convert LDOMString to functor type
2830 //=======================================================================
2831 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
2833 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
2834 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
2835 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
2836 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
2837 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
2838 else if ( theStr.equals( "Area" ) ) return FT_Area;
2839 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
2840 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
2841 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
2842 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
2843 else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface;
2844 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
2845 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
2846 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
2847 else if ( theStr.equals( "Free faces" ) ) return FT_FreeFaces;
2848 else if ( theStr.equals( "Free nodes" ) ) return FT_FreeNodes;
2849 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
2850 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
2851 else if ( theStr.equals( "Length" ) ) return FT_Length;
2852 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
2853 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
2854 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
2855 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
2856 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
2857 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
2858 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
2859 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
2860 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
2861 else if ( theStr.equals( "Color of Group" ) ) return FT_GroupColor;
2862 else if ( theStr.equals( "Linear or Quadratic" ) ) return FT_LinearOrQuadratic;
2863 else if ( theStr.equals( "Element geomtry type" ) ) return FT_ElemGeomType;
2864 else if ( theStr.equals( "" ) ) return FT_Undefined;
2865 else return FT_Undefined;
2868 //=======================================================================
2869 // name : toFunctorType
2870 // Purpose : Convert LDOMString to value of ElementType enumeration
2871 //=======================================================================
2872 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
2874 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
2875 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
2876 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
2877 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
2878 else return SMESH::ALL;
2881 //=======================================================================
2883 // Purpose : Convert ElementType to string
2884 //=======================================================================
2885 static inline LDOMString toString( const SMESH::ElementType theType )
2889 case SMESH::NODE : return "NODE";
2890 case SMESH::EDGE : return "EDGE";
2891 case SMESH::FACE : return "FACE";
2892 case SMESH::VOLUME : return "VOLUME";
2893 case SMESH::ALL : return "ALL";
2894 default : return "";
2898 //=======================================================================
2899 // name : findFilter
2900 // Purpose : Find filter in document
2901 //=======================================================================
2902 static LDOM_Element findFilter( const char* theFilterName,
2903 const LDOM_Document& theDoc,
2904 LDOM_Node* theParent = 0 )
2906 LDOM_Element aRootElement = theDoc.getDocumentElement();
2907 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
2908 return LDOM_Element();
2910 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
2911 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
2913 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
2914 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2916 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
2917 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
2918 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
2920 if ( theParent != 0 )
2921 *theParent = aTypeNode;
2922 return (LDOM_Element&)aFilter;
2926 return LDOM_Element();
2929 //=======================================================================
2930 // name : getSectionName
2931 // Purpose : Get name of section of filters
2932 //=======================================================================
2933 static const char* getSectionName( const ElementType theType )
2937 case SMESH::NODE : return "Filters for nodes";
2938 case SMESH::EDGE : return "Filters for edges";
2939 case SMESH::FACE : return "Filters for faces";
2940 case SMESH::VOLUME : return "Filters for volumes";
2941 case SMESH::ALL : return "Filters for elements";
2942 default : return "";
2946 //=======================================================================
2947 // name : getSection
2948 // Purpose : Create section for filters corresponding to the entity type
2949 //=======================================================================
2950 static LDOM_Node getSection( const ElementType theType,
2951 LDOM_Document& theDoc,
2952 const bool toCreate = false )
2954 LDOM_Element aRootElement = theDoc.getDocumentElement();
2955 if ( aRootElement.isNull() )
2959 bool anExist = false;
2960 const char* aSectionName = getSectionName( theType );
2961 if ( strcmp( aSectionName, "" ) == 0 )
2964 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
2966 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
2968 aNode = aSections.item( i );
2969 LDOM_Element& anItem = ( LDOM_Element& )aNode;
2970 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
2977 // Create new section if necessary
2982 LDOM_Element aNewItem = theDoc.createElement( "section" );
2983 aNewItem.setAttribute( "name", aSectionName );
2984 aRootElement.appendChild( aNewItem );
2994 //=======================================================================
2995 // name : createFilterItem
2996 // Purpose : Create filter item or LDOM document
2997 //=======================================================================
2998 static LDOM_Element createFilterItem( const char* theName,
2999 SMESH::Filter_ptr theFilter,
3000 LDOM_Document& theDoc )
3002 // create new filter in document
3003 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
3004 aFilterItem.setAttribute( "name", theName );
3006 // save filter criterions
3007 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3009 if ( !theFilter->GetCriteria( aCriteria ) )
3010 return LDOM_Element();
3012 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
3014 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
3016 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
3017 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
3018 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
3019 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
3020 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
3022 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
3023 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
3024 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
3025 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
3027 aFilterItem.appendChild( aCriterionItem );
3033 //=======================================================================
3034 // name : FilterLibrary_i::FilterLibrary_i
3035 // Purpose : Constructor
3036 //=======================================================================
3037 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
3039 myFileName = strdup( theFileName );
3040 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
3041 myFilterMgr = aFilterMgr->_this();
3045 // Try to use existing library file
3046 bool anExists = false;
3047 if ( !aParser.parse( myFileName ) )
3049 myDoc = aParser.getDocument();
3052 // Create a new XML document if it doesn't exist
3054 myDoc = LDOM_Document::createDocument( LDOMString() );
3056 LDOM_Element aRootElement = myDoc.getDocumentElement();
3057 if ( aRootElement.isNull() )
3059 // If the existing document is empty --> try to create a new one
3061 myDoc = LDOM_Document::createDocument( LDOMString() );
3065 //=======================================================================
3066 // name : FilterLibrary_i::FilterLibrary_i
3067 // Purpose : Constructor
3068 //=======================================================================
3069 FilterLibrary_i::FilterLibrary_i()
3072 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
3073 myFilterMgr = aFilter->_this();
3075 myDoc = LDOM_Document::createDocument( LDOMString() );
3078 FilterLibrary_i::~FilterLibrary_i()
3081 //TPythonDump()<<this<<".Destroy()";
3084 //=======================================================================
3085 // name : FilterLibrary_i::Copy
3086 // Purpose : Create filter and initialize it with values from library
3087 //=======================================================================
3088 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
3090 Filter_ptr aRes = Filter::_nil();
3091 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
3093 if ( aFilter.isNull() )
3096 std::list<SMESH::Filter::Criterion> aCriteria;
3098 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
3099 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
3101 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
3103 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
3104 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
3105 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
3106 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
3107 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
3109 SMESH::Filter::Criterion aCriterion = createCriterion();
3111 aCriterion.Type = toFunctorType( aTypeStr );
3112 aCriterion.Compare = toFunctorType( aCompareStr );
3113 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
3114 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
3116 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
3118 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
3120 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3121 ? val : atof( str.GetString() );
3123 str = aCrit->getAttribute( ATTR_TOLERANCE );
3124 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3125 ? val : atof( str.GetString() );
3127 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
3128 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
3131 sprintf( a, "%d", val );
3132 aCriterion.ThresholdStr = strdup( a );
3135 aCriterion.ThresholdStr = str.GetString();
3137 aCriteria.push_back( aCriterion );
3140 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
3141 aCriteriaVar->length( aCriteria.size() );
3144 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
3146 for( ; anIter != aCriteria.end(); ++anIter )
3147 aCriteriaVar[ i++ ] = *anIter;
3149 aRes = myFilterMgr->CreateFilter();
3150 aRes->SetCriteria( aCriteriaVar.inout() );
3152 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
3157 //=======================================================================
3158 // name : FilterLibrary_i::SetFileName
3159 // Purpose : Set file name for library
3160 //=======================================================================
3161 void FilterLibrary_i::SetFileName( const char* theFileName )
3164 myFileName = strdup( theFileName );
3165 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
3168 //=======================================================================
3169 // name : FilterLibrary_i::GetFileName
3170 // Purpose : Get file name of library
3171 //=======================================================================
3172 char* FilterLibrary_i::GetFileName()
3174 return CORBA::string_dup( myFileName );
3177 //=======================================================================
3178 // name : FilterLibrary_i::Add
3179 // Purpose : Add new filter to library
3180 //=======================================================================
3181 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
3183 // if filter already in library or entry filter is null do nothing
3184 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3185 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
3188 // get section corresponding to the filter type
3189 ElementType anEntType = theFilter->GetElementType();
3191 LDOM_Node aSection = getSection( anEntType, myDoc, true );
3192 if ( aSection.isNull() )
3195 // create filter item
3196 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
3197 if ( aFilterItem.isNull() )
3201 aSection.appendChild( aFilterItem );
3202 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3203 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
3208 //=======================================================================
3209 // name : FilterLibrary_i::Add
3210 // Purpose : Add new filter to library
3211 //=======================================================================
3212 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
3214 // if filter already in library or entry filter is null do nothing
3215 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3216 if ( !aFilterNode.isNull() )
3219 LDOM_Node aSection = getSection( theType, myDoc, true );
3220 if ( aSection.isNull() )
3223 // create filter item
3224 Filter_var aFilter = myFilterMgr->CreateFilter();
3226 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
3227 if ( aFilterItem.isNull() )
3231 aSection.appendChild( aFilterItem );
3232 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
3237 //=======================================================================
3238 // name : FilterLibrary_i::Delete
3239 // Purpose : Delete filter from library
3240 //=======================================================================
3241 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
3243 LDOM_Node aParentNode;
3244 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
3245 if ( aFilterNode.isNull() || aParentNode.isNull() )
3248 aParentNode.removeChild( aFilterNode );
3249 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
3253 //=======================================================================
3254 // name : FilterLibrary_i::Replace
3255 // Purpose : Replace existing filter with entry filter.
3256 // IMPORTANT : If filter does not exist it is not created
3257 //=======================================================================
3258 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
3259 const char* theNewName,
3260 Filter_ptr theFilter )
3262 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
3263 if ( aFilterItem.isNull() || theFilter->_is_nil() )
3266 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
3267 if ( aNewItem.isNull() )
3271 aFilterItem.ReplaceElement( aNewItem );
3272 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3273 TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
3278 //=======================================================================
3279 // name : FilterLibrary_i::Save
3280 // Purpose : Save library on disk
3281 //=======================================================================
3282 CORBA::Boolean FilterLibrary_i::Save()
3284 if ( myFileName == 0 || strlen( myFileName ) == 0 )
3287 FILE* aOutFile = fopen( myFileName, "wt" );
3291 LDOM_XmlWriter aWriter( aOutFile );
3292 aWriter.SetIndentation( 2 );
3296 TPythonDump()<<this<<".Save()";
3300 //=======================================================================
3301 // name : FilterLibrary_i::SaveAs
3302 // Purpose : Save library on disk
3303 //=======================================================================
3304 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
3306 myFileName = strdup ( aFileName );
3307 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
3311 //=======================================================================
3312 // name : FilterLibrary_i::IsPresent
3313 // Purpose : Verify whether filter is in library
3314 //=======================================================================
3315 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
3317 return !findFilter( theFilterName, myDoc ).isNull();
3320 //=======================================================================
3321 // name : FilterLibrary_i::NbFilters
3322 // Purpose : Return amount of filters in library
3323 //=======================================================================
3324 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
3326 string_array_var aNames = GetNames( theType );
3327 return aNames->length();
3330 //=======================================================================
3331 // name : FilterLibrary_i::GetNames
3332 // Purpose : Get names of filters from library
3333 //=======================================================================
3334 string_array* FilterLibrary_i::GetNames( ElementType theType )
3336 string_array_var anArray = new string_array;
3337 TColStd_SequenceOfHAsciiString aSeq;
3339 LDOM_Node aSection = getSection( theType, myDoc, false );
3341 if ( !aSection.isNull() )
3343 for ( LDOM_Node aFilter = aSection.getFirstChild();
3344 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3346 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
3347 aSeq.Append( new TCollection_HAsciiString(
3348 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
3352 anArray->length( aSeq.Length() );
3353 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
3354 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
3356 return anArray._retn();
3359 //=======================================================================
3360 // name : FilterLibrary_i::GetAllNames
3361 // Purpose : Get names of filters from library
3362 //=======================================================================
3363 string_array* FilterLibrary_i::GetAllNames()
3365 string_array_var aResArray = new string_array;
3366 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
3368 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
3370 int aPrevLength = aResArray->length();
3371 aResArray->length( aPrevLength + aNames->length() );
3372 for ( int i = 0, n = aNames->length(); i < n; i++ )
3373 aResArray[ aPrevLength + i ] = aNames[ i ];
3376 return aResArray._retn();