1 // Copyright (C) 2007-2008 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
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_Filter_i.cxx
24 // Author : Alexey Petrov, OCC
27 #include "SMESH_Filter_i.hxx"
29 #include "SMESH_Gen_i.hxx"
30 #include "SMESH_PythonDump.hxx"
32 #include "SMDS_Mesh.hxx"
33 #include "SMDS_MeshNode.hxx"
34 #include "SMDS_MeshElement.hxx"
35 #include "SMDS_ElemIterator.hxx"
37 #include "SMESHDS_Mesh.hxx"
39 #include <BRep_Tool.hxx>
40 #include <Geom_CylindricalSurface.hxx>
41 #include <Geom_Plane.hxx>
42 #include <LDOMParser.hxx>
43 #include <LDOMString.hxx>
44 #include <LDOM_Document.hxx>
45 #include <LDOM_Element.hxx>
46 #include <LDOM_Node.hxx>
47 #include <LDOM_XmlWriter.hxx>
48 #include <Precision.hxx>
49 #include <TColStd_ListIteratorOfListOfInteger.hxx>
50 #include <TColStd_ListIteratorOfListOfReal.hxx>
51 #include <TColStd_ListOfInteger.hxx>
52 #include <TColStd_ListOfReal.hxx>
53 #include <TColStd_SequenceOfHAsciiString.hxx>
54 #include <TCollection_HAsciiString.hxx>
56 #include <TopExp_Explorer.hxx>
58 #include <TopoDS_Face.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <TopTools_IndexedMapOfShape.hxx>
62 using namespace SMESH;
63 using namespace SMESH::Controls;
69 GetPredicate( Predicate_ptr thePredicate )
71 return DownCast<Predicate_i*>(thePredicate);
78 Description : Predicate for verifying whether entity belongs to
79 specified geometrical support
82 Controls::BelongToGeom::BelongToGeom()
86 myTolerance(Precision::Confusion())
89 void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
91 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
95 void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
101 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
102 const TopoDS_Shape& theShape)
104 if (theMap.Contains(theShape)) return true;
106 if (theShape.ShapeType() == TopAbs_COMPOUND ||
107 theShape.ShapeType() == TopAbs_COMPSOLID)
109 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
110 for (; anIt.More(); anIt.Next())
112 if (!IsSubShape(theMap, anIt.Value())) {
122 void Controls::BelongToGeom::init()
124 if (!myMeshDS || myShape.IsNull()) return;
126 // is subshape of main shape?
127 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
128 if (aMainShape.IsNull()) {
129 myIsSubshape = false;
132 TopTools_IndexedMapOfShape aMap;
133 TopExp::MapShapes(aMainShape, aMap);
134 myIsSubshape = IsSubShape(aMap, myShape);
139 myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
140 myElementsOnShapePtr->SetTolerance(myTolerance);
141 myElementsOnShapePtr->SetAllNodes(true); // belong, while false means "lays on"
142 myElementsOnShapePtr->SetMesh(myMeshDS);
143 myElementsOnShapePtr->SetShape(myShape, myType);
147 static bool IsContains( const SMESHDS_Mesh* theMeshDS,
148 const TopoDS_Shape& theShape,
149 const SMDS_MeshElement* theElem,
150 TopAbs_ShapeEnum theFindShapeEnum,
151 TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE )
153 TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
155 while( anExp.More() )
157 const TopoDS_Shape& aShape = anExp.Current();
158 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
159 if( aSubMesh->Contains( theElem ) )
167 bool Controls::BelongToGeom::IsSatisfy (long theId)
169 if (myMeshDS == 0 || myShape.IsNull())
174 return myElementsOnShapePtr->IsSatisfy(theId);
178 if (myType == SMDSAbs_Node)
180 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
182 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
183 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
184 switch( aTypeOfPosition )
186 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
187 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
188 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
189 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
195 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
197 if( myType == SMDSAbs_All )
199 return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
200 IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
201 IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
202 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
204 else if( myType == anElem->GetType() )
208 case SMDSAbs_Edge : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
209 case SMDSAbs_Face : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
210 case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
211 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
220 void Controls::BelongToGeom::SetType (SMDSAbs_ElementType theType)
226 SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
231 TopoDS_Shape Controls::BelongToGeom::GetShape()
236 const SMESHDS_Mesh* Controls::BelongToGeom::GetMeshDS() const
241 void Controls::BelongToGeom::SetTolerance (double theTolerance)
243 myTolerance = theTolerance;
248 double Controls::BelongToGeom::GetTolerance()
255 Description : Predicate for verifying whether entiy lying or partially lying on
256 specified geometrical support
259 Controls::LyingOnGeom::LyingOnGeom()
263 myTolerance(Precision::Confusion())
266 void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
268 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
272 void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
278 void Controls::LyingOnGeom::init()
280 if (!myMeshDS || myShape.IsNull()) return;
282 // is subshape of main shape?
283 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
284 if (aMainShape.IsNull()) {
285 myIsSubshape = false;
288 TopTools_IndexedMapOfShape aMap;
289 TopExp::MapShapes(aMainShape, aMap);
290 myIsSubshape = IsSubShape(aMap, myShape);
295 myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
296 myElementsOnShapePtr->SetTolerance(myTolerance);
297 myElementsOnShapePtr->SetAllNodes(false); // lays on, while true means "belong"
298 myElementsOnShapePtr->SetMesh(myMeshDS);
299 myElementsOnShapePtr->SetShape(myShape, myType);
303 bool Controls::LyingOnGeom::IsSatisfy( long theId )
305 if ( myMeshDS == 0 || myShape.IsNull() )
310 return myElementsOnShapePtr->IsSatisfy(theId);
314 if( myType == SMDSAbs_Node )
316 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
318 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
319 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
320 switch( aTypeOfPosition )
322 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
323 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
324 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
325 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
331 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
333 if( myType == SMDSAbs_All )
335 return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
336 Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
337 Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
338 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
340 else if( myType == anElem->GetType() )
344 case SMDSAbs_Edge : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
345 case SMDSAbs_Face : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
346 case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
347 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
356 void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
362 SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
367 TopoDS_Shape Controls::LyingOnGeom::GetShape()
372 const SMESHDS_Mesh* Controls::LyingOnGeom::GetMeshDS() const
377 void Controls::LyingOnGeom::SetTolerance (double theTolerance)
379 myTolerance = theTolerance;
384 double Controls::LyingOnGeom::GetTolerance()
389 bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh* theMeshDS,
390 const TopoDS_Shape& theShape,
391 const SMDS_MeshElement* theElem,
392 TopAbs_ShapeEnum theFindShapeEnum,
393 TopAbs_ShapeEnum theAvoidShapeEnum )
395 if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
398 TopTools_IndexedMapOfShape aSubShapes;
399 TopExp::MapShapes( theShape, aSubShapes );
401 for (int i = 1; i <= aSubShapes.Extent(); i++)
403 const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
405 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
406 if( aSubMesh->Contains( theElem ) )
409 SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
410 while ( aNodeIt->more() )
412 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
413 SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
414 while ( anElemIt->more() )
416 const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
417 if (anElement == theElem)
433 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
435 SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
436 return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
441 toArray( const TColStd_ListOfInteger& aList )
443 SMESH::long_array_var anArray = new SMESH::long_array;
444 anArray->length( aList.Extent() );
445 TColStd_ListIteratorOfListOfInteger anIter( aList );
447 for( ; anIter.More(); anIter.Next() )
448 anArray[ i++ ] = anIter.Value();
450 return anArray._retn();
455 toArray( const TColStd_ListOfReal& aList )
457 SMESH::double_array_var anArray = new SMESH::double_array;
458 anArray->length( aList.Extent() );
459 TColStd_ListIteratorOfListOfReal anIter( aList );
461 for( ; anIter.More(); anIter.Next() )
462 anArray[ i++ ] = anIter.Value();
464 return anArray._retn();
467 static SMESH::Filter::Criterion createCriterion()
469 SMESH::Filter::Criterion aCriterion;
471 aCriterion.Type = FT_Undefined;
472 aCriterion.Compare = FT_Undefined;
473 aCriterion.Threshold = 0;
474 aCriterion.UnaryOp = FT_Undefined;
475 aCriterion.BinaryOp = FT_Undefined;
476 aCriterion.ThresholdStr = "";
477 aCriterion.ThresholdID = "";
478 aCriterion.Tolerance = Precision::Confusion();
479 aCriterion.TypeOfElement = SMESH::ALL;
480 aCriterion.Precision = -1;
485 static TopoDS_Shape getShapeByName( const char* theName )
489 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
490 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
491 if (!CORBA::is_nil(aStudy))
493 SALOMEDS::Study::ListOfSObject_var aList =
494 aStudy->FindObjectByName( theName, "GEOM" );
495 if ( aList->length() > 0 )
497 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
498 if ( !aGeomObj->_is_nil() )
500 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
501 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
507 return TopoDS_Shape();
510 static TopoDS_Shape getShapeByID (const char* theID)
512 if (theID != 0 && theID != "") {
513 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
514 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
516 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
517 SALOMEDS::GenericAttribute_var anAttr;
518 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
519 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
520 CORBA::String_var aVal = anIOR->Value();
521 CORBA::Object_var obj = aStudy->ConvertIORToObject(aVal);
522 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
524 if (!aGeomObj->_is_nil()) {
525 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
526 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
532 return TopoDS_Shape();
535 static char* getShapeNameByID (const char* theID)
537 char* aName = (char*)"";
539 if (theID != 0 && theID != "") {
540 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
541 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
543 //SALOMEDS::SObject_var aSObj = aStudy->FindObjectIOR( theID );
544 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
545 SALOMEDS::GenericAttribute_var anAttr;
546 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeName")) {
547 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
548 aName = aNameAttr->Value();
562 Description : An abstact class for all functors
564 Functor_i::Functor_i():
565 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
567 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
568 //PortableServer::ObjectId_var anObjectId =
569 // SMESH_Gen_i::GetPOA()->activate_object( this );
572 Functor_i::~Functor_i()
574 //TPythonDump()<<this<<".Destroy()";
577 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
579 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
580 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
583 ElementType Functor_i::GetElementType()
585 return ( ElementType )myFunctorPtr->GetType();
590 Class : NumericalFunctor_i
591 Description : Base class for numerical functors
593 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
595 return myNumericalFunctorPtr->GetValue( theId );
598 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
600 myNumericalFunctorPtr->SetPrecision( thePrecision );
601 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
604 CORBA::Long NumericalFunctor_i::GetPrecision()
606 return myNumericalFunctorPtr->GetPrecision();
609 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
611 return myNumericalFunctorPtr;
616 Class : SMESH_MinimumAngle
617 Description : Functor for calculation of minimum angle
619 MinimumAngle_i::MinimumAngle_i()
621 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
622 myFunctorPtr = myNumericalFunctorPtr;
625 FunctorType MinimumAngle_i::GetFunctorType()
627 return SMESH::FT_MinimumAngle;
633 Description : Functor for calculating aspect ratio
635 AspectRatio_i::AspectRatio_i()
637 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
638 myFunctorPtr = myNumericalFunctorPtr;
641 FunctorType AspectRatio_i::GetFunctorType()
643 return SMESH::FT_AspectRatio;
648 Class : AspectRatio3D
649 Description : Functor for calculating aspect ratio 3D
651 AspectRatio3D_i::AspectRatio3D_i()
653 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
654 myFunctorPtr = myNumericalFunctorPtr;
657 FunctorType AspectRatio3D_i::GetFunctorType()
659 return SMESH::FT_AspectRatio3D;
665 Description : Functor for calculating warping
667 Warping_i::Warping_i()
669 myNumericalFunctorPtr.reset( new Controls::Warping() );
670 myFunctorPtr = myNumericalFunctorPtr;
673 FunctorType Warping_i::GetFunctorType()
675 return SMESH::FT_Warping;
681 Description : Functor for calculating taper
685 myNumericalFunctorPtr.reset( new Controls::Taper() );
686 myFunctorPtr = myNumericalFunctorPtr;
689 FunctorType Taper_i::GetFunctorType()
691 return SMESH::FT_Taper;
697 Description : Functor for calculating skew in degrees
701 myNumericalFunctorPtr.reset( new Controls::Skew() );
702 myFunctorPtr = myNumericalFunctorPtr;
705 FunctorType Skew_i::GetFunctorType()
707 return SMESH::FT_Skew;
712 Description : Functor for calculating area
716 myNumericalFunctorPtr.reset( new Controls::Area() );
717 myFunctorPtr = myNumericalFunctorPtr;
720 FunctorType Area_i::GetFunctorType()
722 return SMESH::FT_Area;
727 Description : Functor for calculating volume of 3D element
729 Volume3D_i::Volume3D_i()
731 myNumericalFunctorPtr.reset( new Controls::Volume() );
732 myFunctorPtr = myNumericalFunctorPtr;
735 FunctorType Volume3D_i::GetFunctorType()
737 return SMESH::FT_Volume3D;
742 Description : Functor for calculating length off edge
746 myNumericalFunctorPtr.reset( new Controls::Length() );
747 myFunctorPtr = myNumericalFunctorPtr;
750 FunctorType Length_i::GetFunctorType()
752 return SMESH::FT_Length;
757 Description : Functor for calculating length of edge
759 Length2D_i::Length2D_i()
761 myNumericalFunctorPtr.reset( new Controls::Length2D() );
762 myFunctorPtr = myNumericalFunctorPtr;
765 FunctorType Length2D_i::GetFunctorType()
767 return SMESH::FT_Length2D;
770 SMESH::Length2D::Values* Length2D_i::GetValues()
772 INFOS("Length2D_i::GetValues");
773 SMESH::Controls::Length2D::TValues aValues;
774 myLength2DPtr->GetValues( aValues );
776 long i = 0, iEnd = aValues.size();
778 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
780 SMESH::Controls::Length2D::TValues::const_iterator anIter;
781 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
783 const SMESH::Controls::Length2D::Value& aVal = *anIter;
784 SMESH::Length2D::Value &aValue = aResult[ i ];
786 aValue.myLength = aVal.myLength;
787 aValue.myPnt1 = aVal.myPntId[ 0 ];
788 aValue.myPnt2 = aVal.myPntId[ 1 ];
791 INFOS("Length2D_i::GetValuess~");
792 return aResult._retn();
796 Class : MultiConnection_i
797 Description : Functor for calculating number of faces conneted to the edge
799 MultiConnection_i::MultiConnection_i()
801 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
802 myFunctorPtr = myNumericalFunctorPtr;
805 FunctorType MultiConnection_i::GetFunctorType()
807 return SMESH::FT_MultiConnection;
811 Class : MultiConnection2D_i
812 Description : Functor for calculating number of faces conneted to the edge
814 MultiConnection2D_i::MultiConnection2D_i()
816 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
817 myFunctorPtr = myNumericalFunctorPtr;
820 FunctorType MultiConnection2D_i::GetFunctorType()
822 return SMESH::FT_MultiConnection2D;
825 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
827 INFOS("MultiConnection2D_i::GetValues");
828 SMESH::Controls::MultiConnection2D::MValues aValues;
829 myMulticonnection2DPtr->GetValues( aValues );
831 long i = 0, iEnd = aValues.size();
833 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
835 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
836 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
838 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
839 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
841 aValue.myPnt1 = aVal.myPntId[ 0 ];
842 aValue.myPnt2 = aVal.myPntId[ 1 ];
843 aValue.myNbConnects = (*anIter).second;
846 INFOS("Multiconnection2D_i::GetValuess~");
847 return aResult._retn();
857 Description : Base class for all predicates
859 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
861 return myPredicatePtr->IsSatisfy( theId );
864 Controls::PredicatePtr Predicate_i::GetPredicate()
866 return myPredicatePtr;
870 Class : BadOrientedVolume_i
871 Description : Verify whether a mesh volume is incorrectly oriented from
872 the point of view of MED convention
874 BadOrientedVolume_i::BadOrientedVolume_i()
876 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
877 myFunctorPtr = myPredicatePtr = control;
880 FunctorType BadOrientedVolume_i::GetFunctorType()
882 return SMESH::FT_BadOrientedVolume;
886 Class : BelongToGeom_i
887 Description : Predicate for selection on geometrical support
889 BelongToGeom_i::BelongToGeom_i()
891 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
892 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
897 BelongToGeom_i::~BelongToGeom_i()
903 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
905 if ( theGeom->_is_nil() )
907 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
908 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
909 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
910 myBelongToGeomPtr->SetGeom( aLocShape );
911 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
914 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
916 myBelongToGeomPtr->SetGeom( theShape );
919 void BelongToGeom_i::SetElementType(ElementType theType){
920 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
921 TPythonDump()<<this<<".SetElementType("<<theType<<")";
924 FunctorType BelongToGeom_i::GetFunctorType()
926 return SMESH::FT_BelongToGeom;
929 void BelongToGeom_i::SetShapeName( const char* theName )
932 myShapeName = strdup( theName );
933 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
934 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
937 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
940 myShapeName = strdup( theName );
943 myShapeID = strdup( theID );
947 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
948 myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
950 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
953 char* BelongToGeom_i::GetShapeName()
955 return CORBA::string_dup( myShapeName );
958 char* BelongToGeom_i::GetShapeID()
960 return CORBA::string_dup( myShapeID );
963 void BelongToGeom_i::SetTolerance( CORBA::Double theToler )
965 myBelongToGeomPtr->SetTolerance( theToler );
966 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
969 CORBA::Double BelongToGeom_i::GetTolerance()
971 return myBelongToGeomPtr->GetTolerance();
975 Class : BelongToSurface_i
976 Description : Predicate for selection on geometrical support
978 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
980 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
981 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
984 mySurfaceType = theSurfaceType;
987 BelongToSurface_i::~BelongToSurface_i()
993 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
995 if ( theGeom->_is_nil() )
997 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
998 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
999 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1001 if ( aLocShape.ShapeType() == TopAbs_FACE )
1003 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
1004 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
1006 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1011 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
1014 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
1017 myShapeName = strdup( theName );
1018 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1019 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
1022 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
1025 myShapeName = strdup( theName );
1028 myShapeID = strdup( theID );
1032 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1033 myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
1035 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1038 char* BelongToSurface_i::GetShapeName()
1040 return CORBA::string_dup( myShapeName );
1043 char* BelongToSurface_i::GetShapeID()
1045 return CORBA::string_dup( myShapeID );
1048 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
1050 myElementsOnSurfacePtr->SetTolerance( theToler );
1051 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1054 CORBA::Double BelongToSurface_i::GetTolerance()
1056 return myElementsOnSurfacePtr->GetTolerance();
1059 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
1061 myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
1062 TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
1065 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
1067 return myElementsOnSurfacePtr->GetUseBoundaries();
1072 Class : BelongToPlane_i
1073 Description : Verify whether mesh element lie in pointed Geom planar object
1076 BelongToPlane_i::BelongToPlane_i()
1077 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
1081 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1083 BelongToSurface_i::SetSurface( theGeom, theType );
1084 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
1087 FunctorType BelongToPlane_i::GetFunctorType()
1089 return FT_BelongToPlane;
1093 Class : BelongToCylinder_i
1094 Description : Verify whether mesh element lie in pointed Geom planar object
1097 BelongToCylinder_i::BelongToCylinder_i()
1098 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1102 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1104 BelongToSurface_i::SetSurface( theGeom, theType );
1105 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
1108 FunctorType BelongToCylinder_i::GetFunctorType()
1110 return FT_BelongToCylinder;
1114 Class : BelongToGenSurface_i
1115 Description : Verify whether mesh element lie in pointed Geom planar object
1118 BelongToGenSurface_i::BelongToGenSurface_i()
1119 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1123 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1125 if ( theGeom->_is_nil() )
1127 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1128 if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1129 aLocShape.Nullify();
1131 BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1132 TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1135 FunctorType BelongToGenSurface_i::GetFunctorType()
1137 return FT_BelongToGenSurface;
1141 Class : LyingOnGeom_i
1142 Description : Predicate for selection on geometrical support
1144 LyingOnGeom_i::LyingOnGeom_i()
1146 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1147 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1152 LyingOnGeom_i::~LyingOnGeom_i()
1158 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1160 if ( theGeom->_is_nil() )
1162 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1163 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1164 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1165 myLyingOnGeomPtr->SetGeom( aLocShape );
1166 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1169 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1171 myLyingOnGeomPtr->SetGeom( theShape );
1174 void LyingOnGeom_i::SetElementType(ElementType theType){
1175 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1176 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1179 FunctorType LyingOnGeom_i::GetFunctorType()
1181 return SMESH::FT_LyingOnGeom;
1184 void LyingOnGeom_i::SetShapeName( const char* theName )
1187 myShapeName = strdup( theName );
1188 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1189 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1192 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1195 myShapeName = strdup( theName );
1198 myShapeID = strdup( theID );
1202 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1203 myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
1205 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1208 char* LyingOnGeom_i::GetShapeName()
1210 return CORBA::string_dup( myShapeName );
1213 char* LyingOnGeom_i::GetShapeID()
1215 return CORBA::string_dup( myShapeID );
1218 void LyingOnGeom_i::SetTolerance( CORBA::Double theToler )
1220 myLyingOnGeomPtr->SetTolerance( theToler );
1221 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1224 CORBA::Double LyingOnGeom_i::GetTolerance()
1226 return myLyingOnGeomPtr->GetTolerance();
1230 Class : FreeBorders_i
1231 Description : Predicate for free borders
1233 FreeBorders_i::FreeBorders_i()
1235 myPredicatePtr.reset(new Controls::FreeBorders());
1236 myFunctorPtr = myPredicatePtr;
1239 FunctorType FreeBorders_i::GetFunctorType()
1241 return SMESH::FT_FreeBorders;
1246 Description : Predicate for free borders
1248 FreeEdges_i::FreeEdges_i()
1249 : myFreeEdgesPtr( new Controls::FreeEdges() )
1251 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1254 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1256 INFOS("FreeEdges_i::GetBorders");
1257 SMESH::Controls::FreeEdges::TBorders aBorders;
1258 myFreeEdgesPtr->GetBoreders( aBorders );
1260 long i = 0, iEnd = aBorders.size();
1262 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1263 aResult->length(iEnd);
1265 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1266 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1268 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1269 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1271 aBorder.myElemId = aBord.myElemId;
1272 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1273 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1276 INFOS("FreeEdges_i::GetBorders~");
1277 return aResult._retn();
1280 FunctorType FreeEdges_i::GetFunctorType()
1282 return SMESH::FT_FreeEdges;
1287 Description : Predicate for free faces
1289 FreeFaces_i::FreeFaces_i()
1291 myPredicatePtr.reset(new Controls::FreeFaces());
1292 myFunctorPtr = myPredicatePtr;
1295 FunctorType FreeFaces_i::GetFunctorType()
1297 return SMESH::FT_FreeFaces;
1302 Description : Predicate for free nodes
1304 FreeNodes_i::FreeNodes_i()
1306 myPredicatePtr.reset(new Controls::FreeNodes());
1307 myFunctorPtr = myPredicatePtr;
1310 FunctorType FreeNodes_i::GetFunctorType()
1312 return SMESH::FT_FreeNodes;
1316 Class : RangeOfIds_i
1317 Description : Predicate for Range of Ids.
1318 Range may be specified with two ways.
1319 1. Using AddToRange method
1320 2. With SetRangeStr method. Parameter of this method is a string
1321 like as "1,2,3,50-60,63,67,70-"
1324 RangeOfIds_i::RangeOfIds_i()
1326 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1327 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1330 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1332 CORBA::Long iEnd = theIds.length();
1333 for ( CORBA::Long i = 0; i < iEnd; i++ )
1334 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1335 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1338 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1340 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1341 return myRangeOfIdsPtr->SetRangeStr(
1342 TCollection_AsciiString( (Standard_CString)theRange ) );
1345 char* RangeOfIds_i::GetRangeStr()
1347 TCollection_AsciiString aStr;
1348 myRangeOfIdsPtr->GetRangeStr( aStr );
1349 return CORBA::string_dup( aStr.ToCString() );
1352 void RangeOfIds_i::SetElementType( ElementType theType )
1354 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1355 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1358 FunctorType RangeOfIds_i::GetFunctorType()
1360 return SMESH::FT_RangeOfIds;
1364 Class : LinearOrQuadratic_i
1365 Description : Predicate to verify whether a mesh element is linear
1367 LinearOrQuadratic_i::LinearOrQuadratic_i()
1369 myLinearOrQuadraticPtr.reset(new Controls::LinearOrQuadratic());
1370 myFunctorPtr = myPredicatePtr = myLinearOrQuadraticPtr;
1373 void LinearOrQuadratic_i::SetElementType(ElementType theType)
1375 myLinearOrQuadraticPtr->SetType(SMDSAbs_ElementType(theType));
1376 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1379 FunctorType LinearOrQuadratic_i::GetFunctorType()
1381 return SMESH::FT_LinearOrQuadratic;
1385 Class : GroupColor_i
1386 Description : Functor for check color of group to whic mesh element belongs to
1388 GroupColor_i::GroupColor_i()
1390 myGroupColorPtr.reset(new Controls::GroupColor());
1391 myFunctorPtr = myPredicatePtr = myGroupColorPtr;
1394 FunctorType GroupColor_i::GetFunctorType()
1396 return SMESH::FT_GroupColor;
1399 void GroupColor_i::SetColorStr( const char* theColor )
1401 myGroupColorPtr->SetColorStr(
1402 TCollection_AsciiString( (Standard_CString)theColor ) );
1403 TPythonDump()<<this<<".SetColorStr('"<<theColor<<"')";
1406 char* GroupColor_i::GetColorStr()
1408 TCollection_AsciiString aStr;
1409 myGroupColorPtr->GetColorStr( aStr );
1410 return CORBA::string_dup( aStr.ToCString() );
1413 void GroupColor_i::SetElementType(ElementType theType)
1415 myGroupColorPtr->SetType(SMDSAbs_ElementType(theType));
1416 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1420 Class : ElemGeomType_i
1421 Description : Predicate check is element has indicated geometry type
1423 ElemGeomType_i::ElemGeomType_i()
1425 myElemGeomTypePtr.reset(new Controls::ElemGeomType());
1426 myFunctorPtr = myPredicatePtr = myElemGeomTypePtr;
1429 void ElemGeomType_i::SetElementType(ElementType theType)
1431 myElemGeomTypePtr->SetType(SMDSAbs_ElementType(theType));
1432 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1435 void ElemGeomType_i::SetGeometryType(GeometryType theType)
1437 myElemGeomTypePtr->SetGeomType(SMDSAbs_GeometryType(theType));
1438 TPythonDump()<<this<<".SetGeometryType("<<theType<<")";
1441 GeometryType ElemGeomType_i::GetGeometryType() const
1443 return (GeometryType)myElemGeomTypePtr->GetGeomType();;
1446 FunctorType ElemGeomType_i::GetFunctorType()
1448 return SMESH::FT_ElemGeomType;
1452 Class : Comparator_i
1453 Description : Base class for comparators
1455 Comparator_i::Comparator_i():
1456 myNumericalFunctor( NULL )
1459 Comparator_i::~Comparator_i()
1461 if ( myNumericalFunctor )
1462 myNumericalFunctor->Destroy();
1465 void Comparator_i::SetMargin( CORBA::Double theValue )
1467 myComparatorPtr->SetMargin( theValue );
1468 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1471 CORBA::Double Comparator_i::GetMargin()
1473 return myComparatorPtr->GetMargin();
1476 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1478 if ( myNumericalFunctor )
1479 myNumericalFunctor->Destroy();
1481 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1483 if ( myNumericalFunctor )
1485 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1486 myNumericalFunctor->Register();
1487 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1491 Controls::ComparatorPtr Comparator_i::GetComparator()
1493 return myComparatorPtr;
1496 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1498 return myNumericalFunctor;
1504 Description : Comparator "<"
1506 LessThan_i::LessThan_i()
1508 myComparatorPtr.reset( new Controls::LessThan() );
1509 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1512 FunctorType LessThan_i::GetFunctorType()
1514 return SMESH::FT_LessThan;
1520 Description : Comparator ">"
1522 MoreThan_i::MoreThan_i()
1524 myComparatorPtr.reset( new Controls::MoreThan() );
1525 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1528 FunctorType MoreThan_i::GetFunctorType()
1530 return SMESH::FT_MoreThan;
1536 Description : Comparator "="
1538 EqualTo_i::EqualTo_i()
1539 : myEqualToPtr( new Controls::EqualTo() )
1541 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1544 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1546 myEqualToPtr->SetTolerance( theToler );
1547 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1550 CORBA::Double EqualTo_i::GetTolerance()
1552 return myEqualToPtr->GetTolerance();
1555 FunctorType EqualTo_i::GetFunctorType()
1557 return SMESH::FT_EqualTo;
1561 Class : LogicalNOT_i
1562 Description : Logical NOT predicate
1564 LogicalNOT_i::LogicalNOT_i()
1565 : myPredicate( NULL ),
1566 myLogicalNOTPtr( new Controls::LogicalNOT() )
1568 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1571 LogicalNOT_i::~LogicalNOT_i()
1574 myPredicate->Destroy();
1577 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1580 myPredicate->Destroy();
1582 myPredicate = SMESH::GetPredicate(thePredicate);
1585 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1586 myPredicate->Register();
1587 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1591 FunctorType LogicalNOT_i::GetFunctorType()
1593 return SMESH::FT_LogicalNOT;
1596 Predicate_i* LogicalNOT_i::GetPredicate_i()
1603 Class : LogicalBinary_i
1604 Description : Base class for binary logical predicate
1606 LogicalBinary_i::LogicalBinary_i()
1607 : myPredicate1( NULL ),
1608 myPredicate2( NULL )
1611 LogicalBinary_i::~LogicalBinary_i()
1614 myPredicate1->Destroy();
1617 myPredicate2->Destroy();
1620 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1623 myPredicate1->SetMesh( theMesh );
1626 myPredicate2->SetMesh( theMesh );
1629 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1632 myPredicate1->Destroy();
1634 myPredicate1 = SMESH::GetPredicate(thePredicate);
1636 if ( myPredicate1 ){
1637 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1638 myPredicate1->Register();
1639 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1643 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1646 myPredicate2->Destroy();
1648 myPredicate2 = SMESH::GetPredicate(thePredicate);
1650 if ( myPredicate2 ){
1651 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1652 myPredicate2->Register();
1653 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1657 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1659 return myLogicalBinaryPtr;
1662 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1664 return myPredicate1;
1666 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1668 return myPredicate2;
1673 Class : LogicalAND_i
1674 Description : Logical AND
1676 LogicalAND_i::LogicalAND_i()
1678 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1679 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1682 FunctorType LogicalAND_i::GetFunctorType()
1684 return SMESH::FT_LogicalAND;
1690 Description : Logical OR
1692 LogicalOR_i::LogicalOR_i()
1694 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1695 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1698 FunctorType LogicalOR_i::GetFunctorType()
1700 return SMESH::FT_LogicalOR;
1708 FilterManager_i::FilterManager_i()
1709 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1711 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
1712 //PortableServer::ObjectId_var anObjectId =
1713 // SMESH_Gen_i::GetPOA()->activate_object( this );
1717 FilterManager_i::~FilterManager_i()
1719 //TPythonDump()<<this<<".Destroy()";
1723 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1725 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1726 SMESH::MinimumAngle_var anObj = aServant->_this();
1727 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1728 return anObj._retn();
1732 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1734 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1735 SMESH::AspectRatio_var anObj = aServant->_this();
1736 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1737 return anObj._retn();
1741 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1743 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1744 SMESH::AspectRatio3D_var anObj = aServant->_this();
1745 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1746 return anObj._retn();
1750 Warping_ptr FilterManager_i::CreateWarping()
1752 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1753 SMESH::Warping_var anObj = aServant->_this();
1754 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1755 return anObj._retn();
1759 Taper_ptr FilterManager_i::CreateTaper()
1761 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1762 SMESH::Taper_var anObj = aServant->_this();
1763 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1764 return anObj._retn();
1768 Skew_ptr FilterManager_i::CreateSkew()
1770 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1771 SMESH::Skew_var anObj = aServant->_this();
1772 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1773 return anObj._retn();
1777 Area_ptr FilterManager_i::CreateArea()
1779 SMESH::Area_i* aServant = new SMESH::Area_i();
1780 SMESH::Area_var anObj = aServant->_this();
1781 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1782 return anObj._retn();
1786 Volume3D_ptr FilterManager_i::CreateVolume3D()
1788 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
1789 SMESH::Volume3D_var anObj = aServant->_this();
1790 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
1791 return anObj._retn();
1795 Length_ptr FilterManager_i::CreateLength()
1797 SMESH::Length_i* aServant = new SMESH::Length_i();
1798 SMESH::Length_var anObj = aServant->_this();
1799 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1800 return anObj._retn();
1803 Length2D_ptr FilterManager_i::CreateLength2D()
1805 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1806 SMESH::Length2D_var anObj = aServant->_this();
1807 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1808 return anObj._retn();
1811 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1813 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1814 SMESH::MultiConnection_var anObj = aServant->_this();
1815 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1816 return anObj._retn();
1819 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1821 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1822 SMESH::MultiConnection2D_var anObj = aServant->_this();
1823 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
1824 return anObj._retn();
1827 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1829 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1830 SMESH::BelongToGeom_var anObj = aServant->_this();
1831 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
1832 return anObj._retn();
1835 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1837 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1838 SMESH::BelongToPlane_var anObj = aServant->_this();
1839 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
1840 return anObj._retn();
1843 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1845 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1846 SMESH::BelongToCylinder_var anObj = aServant->_this();
1847 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
1848 return anObj._retn();
1851 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
1853 SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
1854 SMESH::BelongToGenSurface_var anObj = aServant->_this();
1855 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
1856 return anObj._retn();
1859 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
1861 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
1862 SMESH::LyingOnGeom_var anObj = aServant->_this();
1863 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
1864 return anObj._retn();
1867 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1869 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1870 SMESH::FreeBorders_var anObj = aServant->_this();
1871 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
1872 return anObj._retn();
1875 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1877 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1878 SMESH::FreeEdges_var anObj = aServant->_this();
1879 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
1880 return anObj._retn();
1883 FreeFaces_ptr FilterManager_i::CreateFreeFaces()
1885 SMESH::FreeFaces_i* aServant = new SMESH::FreeFaces_i();
1886 SMESH::FreeFaces_var anObj = aServant->_this();
1887 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeFaces()";
1888 return anObj._retn();
1891 FreeNodes_ptr FilterManager_i::CreateFreeNodes()
1893 SMESH::FreeNodes_i* aServant = new SMESH::FreeNodes_i();
1894 SMESH::FreeNodes_var anObj = aServant->_this();
1895 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeNodes()";
1896 return anObj._retn();
1899 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1901 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1902 SMESH::RangeOfIds_var anObj = aServant->_this();
1903 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
1904 return anObj._retn();
1907 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
1909 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
1910 SMESH::BadOrientedVolume_var anObj = aServant->_this();
1911 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
1912 return anObj._retn();
1915 LessThan_ptr FilterManager_i::CreateLessThan()
1917 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1918 SMESH::LessThan_var anObj = aServant->_this();
1919 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
1920 return anObj._retn();
1923 MoreThan_ptr FilterManager_i::CreateMoreThan()
1925 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1926 SMESH::MoreThan_var anObj = aServant->_this();
1927 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
1928 return anObj._retn();
1931 EqualTo_ptr FilterManager_i::CreateEqualTo()
1933 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1934 SMESH::EqualTo_var anObj = aServant->_this();
1935 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
1936 return anObj._retn();
1939 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1941 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1942 SMESH::LogicalNOT_var anObj = aServant->_this();
1943 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
1944 return anObj._retn();
1947 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
1949 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
1950 SMESH::LogicalAND_var anObj = aServant->_this();
1951 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
1952 return anObj._retn();
1955 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
1957 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
1958 SMESH::LogicalOR_var anObj = aServant->_this();
1959 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
1960 return anObj._retn();
1963 LinearOrQuadratic_ptr FilterManager_i::CreateLinearOrQuadratic()
1965 SMESH::LinearOrQuadratic_i* aServant = new SMESH::LinearOrQuadratic_i();
1966 SMESH::LinearOrQuadratic_var anObj = aServant->_this();
1967 TPythonDump()<<aServant<<" = "<<this<<".CreateLinearOrQuadratic()";
1968 return anObj._retn();
1971 GroupColor_ptr FilterManager_i::CreateGroupColor()
1973 SMESH::GroupColor_i* aServant = new SMESH::GroupColor_i();
1974 SMESH::GroupColor_var anObj = aServant->_this();
1975 TPythonDump()<<aServant<<" = "<<this<<".CreateGroupColor()";
1976 return anObj._retn();
1979 ElemGeomType_ptr FilterManager_i::CreateElemGeomType()
1981 SMESH::ElemGeomType_i* aServant = new SMESH::ElemGeomType_i();
1982 SMESH::ElemGeomType_var anObj = aServant->_this();
1983 TPythonDump()<<aServant<<" = "<<this<<".CreateElemGeomType()";
1984 return anObj._retn();
1987 Filter_ptr FilterManager_i::CreateFilter()
1989 SMESH::Filter_i* aServant = new SMESH::Filter_i();
1990 SMESH::Filter_var anObj = aServant->_this();
1991 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
1992 return anObj._retn();
1995 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
1997 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
1998 SMESH::FilterLibrary_var anObj = aServant->_this();
1999 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary('"<<aFileName<<"')";
2000 return anObj._retn();
2003 FilterLibrary_ptr FilterManager_i::CreateLibrary()
2005 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
2006 SMESH::FilterLibrary_var anObj = aServant->_this();
2007 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
2008 return anObj._retn();
2011 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
2013 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
2014 return remove( aFileName ) ? false : true;
2017 //=============================================================================
2019 * SMESH_Gen_i::CreateFilterManager
2021 * Create filter manager
2023 //=============================================================================
2025 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
2027 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2028 SMESH::FilterManager_var anObj = aFilter->_this();
2029 return anObj._retn();
2037 //=======================================================================
2038 // name : Filter_i::Filter_i
2039 // Purpose : Constructor
2040 //=======================================================================
2041 Filter_i::Filter_i()
2042 : myPredicate( NULL )
2045 //=======================================================================
2046 // name : Filter_i::~Filter_i
2047 // Purpose : Destructor
2048 //=======================================================================
2049 Filter_i::~Filter_i()
2052 myPredicate->Destroy();
2054 if(!CORBA::is_nil(myMesh))
2057 //TPythonDump()<<this<<".Destroy()";
2060 //=======================================================================
2061 // name : Filter_i::SetPredicate
2062 // Purpose : Set predicate
2063 //=======================================================================
2064 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
2067 myPredicate->Destroy();
2069 myPredicate = SMESH::GetPredicate(thePredicate);
2073 myFilter.SetPredicate( myPredicate->GetPredicate() );
2074 myPredicate->Register();
2075 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
2079 //=======================================================================
2080 // name : Filter_i::GetElementType
2081 // Purpose : Get entity type
2082 //=======================================================================
2083 SMESH::ElementType Filter_i::GetElementType()
2085 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
2088 //=======================================================================
2089 // name : Filter_i::SetMesh
2090 // Purpose : Set mesh
2091 //=======================================================================
2094 SetMesh( SMESH_Mesh_ptr theMesh )
2096 if(!CORBA::is_nil(theMesh))
2097 theMesh->Register();
2099 if(!CORBA::is_nil(myMesh))
2102 myMesh = SMESH_Mesh::_duplicate( theMesh );
2103 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
2110 return GetElementsId(myMesh);
2113 //=======================================================================
2114 // name : Filter_i::GetElementsId
2115 // Purpose : Get ids of entities
2116 //=======================================================================
2119 GetElementsId( Predicate_i* thePredicate,
2120 const SMDS_Mesh* theMesh,
2121 Controls::Filter::TIdSequence& theSequence )
2124 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
2129 GetElementsId( Predicate_i* thePredicate,
2130 SMESH_Mesh_ptr theMesh,
2131 Controls::Filter::TIdSequence& theSequence )
2134 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2135 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
2140 GetElementsId( SMESH_Mesh_ptr theMesh )
2142 SMESH::long_array_var anArray = new SMESH::long_array;
2143 if(!CORBA::is_nil(theMesh) && myPredicate){
2144 Controls::Filter::TIdSequence aSequence;
2145 GetElementsId(myPredicate,theMesh,aSequence);
2146 long i = 0, iEnd = aSequence.size();
2147 anArray->length( iEnd );
2148 for ( ; i < iEnd; i++ )
2149 anArray[ i ] = aSequence[i];
2151 return anArray._retn();
2154 template<class TElement, class TIterator, class TPredicate>
2155 static void collectMeshInfo(const TIterator& theItr,
2156 TPredicate& thePred,
2157 SMESH::long_array& theRes)
2161 while (theItr->more()) {
2162 const SMDS_MeshElement* anElem = theItr->next();
2163 if ( thePred->IsSatisfy( anElem->GetID() ) )
2164 theRes[ anElem->GetEntityType() ]++;
2168 //=============================================================================
2170 * \brief Returns statistic of mesh elements
2172 //=============================================================================
2173 SMESH::long_array* ::Filter_i::GetMeshInfo()
2175 SMESH::long_array_var aRes = new SMESH::long_array();
2176 aRes->length(SMESH::Entity_Last);
2177 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
2180 if(!CORBA::is_nil(myMesh) && myPredicate) {
2181 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2182 SMDS_ElemIteratorPtr it;
2183 switch( GetElementType() )
2186 collectMeshInfo<const SMDS_MeshNode*>(aMesh->nodesIterator(),myPredicate,aRes);
2189 collectMeshInfo<const SMDS_MeshElement*>(aMesh->edgesIterator(),myPredicate,aRes);
2192 collectMeshInfo<const SMDS_MeshElement*>(aMesh->facesIterator(),myPredicate,aRes);
2194 case SMDSAbs_Volume:
2195 collectMeshInfo<const SMDS_MeshElement*>(aMesh->volumesIterator(),myPredicate,aRes);
2199 collectMeshInfo<const SMDS_MeshElement*>(aMesh->elementsIterator(),myPredicate,aRes);
2205 return aRes._retn();
2208 //=======================================================================
2209 // name : getCriteria
2210 // Purpose : Retrieve criterions from predicate
2211 //=======================================================================
2212 static inline bool getCriteria( Predicate_i* thePred,
2213 SMESH::Filter::Criteria_out theCriteria )
2215 int aFType = thePred->GetFunctorType();
2219 case FT_FreeBorders:
2222 case FT_LinearOrQuadratic:
2225 CORBA::ULong i = theCriteria->length();
2226 theCriteria->length( i + 1 );
2228 theCriteria[ i ] = createCriterion();
2230 theCriteria[ i ].Type = aFType;
2231 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
2234 case FT_BelongToGeom:
2236 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
2238 CORBA::ULong i = theCriteria->length();
2239 theCriteria->length( i + 1 );
2241 theCriteria[ i ] = createCriterion();
2243 theCriteria[ i ].Type = FT_BelongToGeom;
2244 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2245 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2246 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2247 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2251 case FT_BelongToPlane:
2252 case FT_BelongToCylinder:
2253 case FT_BelongToGenSurface:
2255 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
2257 CORBA::ULong i = theCriteria->length();
2258 theCriteria->length( i + 1 );
2260 theCriteria[ i ] = createCriterion();
2262 theCriteria[ i ].Type = aFType;
2263 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2264 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2265 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2266 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2270 case FT_LyingOnGeom:
2272 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
2274 CORBA::ULong i = theCriteria->length();
2275 theCriteria->length( i + 1 );
2277 theCriteria[ i ] = createCriterion();
2279 theCriteria[ i ].Type = FT_LyingOnGeom;
2280 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2281 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2282 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2283 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2289 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
2291 CORBA::ULong i = theCriteria->length();
2292 theCriteria->length( i + 1 );
2294 theCriteria[ i ] = createCriterion();
2296 theCriteria[ i ].Type = FT_RangeOfIds;
2297 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
2298 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2302 case FT_BadOrientedVolume:
2304 BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
2306 CORBA::ULong i = theCriteria->length();
2307 theCriteria->length( i + 1 );
2309 theCriteria[ i ] = createCriterion();
2311 theCriteria[ i ].Type = FT_BadOrientedVolume;
2312 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2320 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
2322 CORBA::ULong i = theCriteria->length();
2323 theCriteria->length( i + 1 );
2325 theCriteria[ i ] = createCriterion();
2327 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
2328 theCriteria[ i ].Compare = aFType;
2329 theCriteria[ i ].Threshold = aCompar->GetMargin();
2330 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
2332 if ( aFType == FT_EqualTo )
2334 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
2335 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
2342 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2343 getCriteria( aPred, theCriteria );
2344 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2351 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2352 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2353 if ( !getCriteria( aPred1, theCriteria ) )
2355 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2356 return getCriteria( aPred2, theCriteria );
2360 CORBA::ULong i = theCriteria->length();
2361 theCriteria->length( i + 1 );
2363 theCriteria[ i ] = createCriterion();
2365 GroupColor_i* aPred = dynamic_cast<GroupColor_i*>( thePred );
2366 theCriteria[ i ].Type = aFType;
2367 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2368 theCriteria[ i ].ThresholdStr = aPred->GetColorStr();
2372 case FT_ElemGeomType:
2374 CORBA::ULong i = theCriteria->length();
2375 theCriteria->length( i + 1 );
2377 theCriteria[ i ] = createCriterion();
2379 ElemGeomType_i* aPred = dynamic_cast<ElemGeomType_i*>( thePred );
2380 theCriteria[ i ].Type = aFType;
2381 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2382 theCriteria[ i ].Threshold = (double)aPred->GetGeometryType();
2393 //=======================================================================
2394 // name : Filter_i::GetCriteria
2395 // Purpose : Retrieve criterions from predicate
2396 //=======================================================================
2397 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2399 theCriteria = new SMESH::Filter::Criteria;
2400 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2403 //=======================================================================
2404 // name : Filter_i::SetCriteria
2405 // Purpose : Create new predicate and set criterions in it
2406 //=======================================================================
2407 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2409 if ( myPredicate != 0 )
2410 myPredicate->Destroy();
2412 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2413 FilterManager_ptr aFilterMgr = aFilter->_this();
2415 // CREATE two lists ( PREDICATES and LOG OP )
2418 TPythonDump()<<"aCriteria = []";
2419 std::list<SMESH::Predicate_ptr> aPredicates;
2420 std::list<int> aBinaries;
2421 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2423 int aCriterion = theCriteria[ i ].Type;
2424 int aCompare = theCriteria[ i ].Compare;
2425 double aThreshold = theCriteria[ i ].Threshold;
2426 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2427 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2428 int aUnary = theCriteria[ i ].UnaryOp;
2429 int aBinary = theCriteria[ i ].BinaryOp;
2430 double aTolerance = theCriteria[ i ].Tolerance;
2431 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
2432 long aPrecision = theCriteria[ i ].Precision;
2436 pd << "aCriterion = SMESH.Filter.Criterion(" << aCriterion << "," << aCompare
2437 << "," << aThreshold << ",'" << aThresholdStr;
2438 if (aThresholdID && strlen(aThresholdID))
2439 //pd << "',salome.ObjectToID(" << aThresholdID
2440 pd << "','" << aThresholdID
2441 << "'," << aUnary << "," << aBinary << "," << aTolerance
2442 << "," << aTypeOfElem << "," << aPrecision << ")";
2444 pd << "',''," << aUnary << "," << aBinary << "," << aTolerance
2445 << "," << aTypeOfElem << "," << aPrecision << ")";
2448 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2449 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2451 switch ( aCriterion )
2455 case SMESH::FT_MultiConnection:
2456 aFunctor = aFilterMgr->CreateMultiConnection();
2458 case SMESH::FT_MultiConnection2D:
2459 aFunctor = aFilterMgr->CreateMultiConnection2D();
2461 case SMESH::FT_Length:
2462 aFunctor = aFilterMgr->CreateLength();
2464 case SMESH::FT_Length2D:
2465 aFunctor = aFilterMgr->CreateLength2D();
2467 case SMESH::FT_AspectRatio:
2468 aFunctor = aFilterMgr->CreateAspectRatio();
2470 case SMESH::FT_AspectRatio3D:
2471 aFunctor = aFilterMgr->CreateAspectRatio3D();
2473 case SMESH::FT_Warping:
2474 aFunctor = aFilterMgr->CreateWarping();
2476 case SMESH::FT_MinimumAngle:
2477 aFunctor = aFilterMgr->CreateMinimumAngle();
2479 case SMESH::FT_Taper:
2480 aFunctor = aFilterMgr->CreateTaper();
2482 case SMESH::FT_Skew:
2483 aFunctor = aFilterMgr->CreateSkew();
2485 case SMESH::FT_Area:
2486 aFunctor = aFilterMgr->CreateArea();
2488 case SMESH::FT_Volume3D:
2489 aFunctor = aFilterMgr->CreateVolume3D();
2494 case SMESH::FT_FreeBorders:
2495 aPredicate = aFilterMgr->CreateFreeBorders();
2497 case SMESH::FT_FreeEdges:
2498 aPredicate = aFilterMgr->CreateFreeEdges();
2500 case SMESH::FT_FreeFaces:
2501 aPredicate = aFilterMgr->CreateFreeFaces();
2503 case SMESH::FT_FreeNodes:
2504 aPredicate = aFilterMgr->CreateFreeNodes();
2506 case SMESH::FT_BelongToGeom:
2508 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2509 tmpPred->SetElementType( aTypeOfElem );
2510 tmpPred->SetShape( aThresholdID, aThresholdStr );
2511 tmpPred->SetTolerance( aTolerance );
2512 aPredicate = tmpPred;
2515 case SMESH::FT_BelongToPlane:
2516 case SMESH::FT_BelongToCylinder:
2517 case SMESH::FT_BelongToGenSurface:
2519 SMESH::BelongToSurface_ptr tmpPred;
2520 switch ( aCriterion ) {
2521 case SMESH::FT_BelongToPlane:
2522 tmpPred = aFilterMgr->CreateBelongToPlane(); break;
2523 case SMESH::FT_BelongToCylinder:
2524 tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
2526 tmpPred = aFilterMgr->CreateBelongToGenSurface();
2528 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2529 tmpPred->SetTolerance( aTolerance );
2530 aPredicate = tmpPred;
2533 case SMESH::FT_LyingOnGeom:
2535 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2536 tmpPred->SetElementType( aTypeOfElem );
2537 tmpPred->SetShape( aThresholdID, aThresholdStr );
2538 tmpPred->SetTolerance( aTolerance );
2539 aPredicate = tmpPred;
2542 case SMESH::FT_RangeOfIds:
2544 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2545 tmpPred->SetRangeStr( aThresholdStr );
2546 tmpPred->SetElementType( aTypeOfElem );
2547 aPredicate = tmpPred;
2550 case SMESH::FT_BadOrientedVolume:
2552 aPredicate = aFilterMgr->CreateBadOrientedVolume();
2555 case SMESH::FT_LinearOrQuadratic:
2557 SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
2558 tmpPred->SetElementType( aTypeOfElem );
2559 aPredicate = tmpPred;
2562 case SMESH::FT_GroupColor:
2564 SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor();
2565 tmpPred->SetElementType( aTypeOfElem );
2566 tmpPred->SetColorStr( aThresholdStr );
2567 aPredicate = tmpPred;
2570 case SMESH::FT_ElemGeomType:
2572 SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType();
2573 tmpPred->SetElementType( aTypeOfElem );
2574 tmpPred->SetGeometryType( (GeometryType)(int)(aThreshold + 0.5) );
2575 aPredicate = tmpPred;
2584 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
2586 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
2588 if ( aCompare == SMESH::FT_LessThan )
2589 aComparator = aFilterMgr->CreateLessThan();
2590 else if ( aCompare == SMESH::FT_MoreThan )
2591 aComparator = aFilterMgr->CreateMoreThan();
2592 else if ( aCompare == SMESH::FT_EqualTo )
2593 aComparator = aFilterMgr->CreateEqualTo();
2597 aComparator->SetNumFunctor( aFunctor );
2598 aComparator->SetMargin( aThreshold );
2600 if ( aCompare == FT_EqualTo )
2602 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
2603 anEqualTo->SetTolerance( aTolerance );
2606 aPredicate = aComparator;
2608 aFunctor->SetPrecision( aPrecision );
2612 if ( aUnary == FT_LogicalNOT )
2614 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
2615 aNotPred->SetPredicate( aPredicate );
2616 aPredicate = aNotPred;
2620 aPredicates.push_back( aPredicate );
2621 aBinaries.push_back( aBinary );
2622 TPythonDump()<<"aCriteria.append(aCriterion)";
2625 TPythonDump()<<this<<".SetCriteria(aCriteria)";
2627 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
2629 // combine all "AND" operations
2631 std::list<SMESH::Predicate_ptr> aResList;
2633 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
2634 std::list<int>::iterator aBinaryIter;
2636 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
2637 int aPrevBinary = SMESH::FT_Undefined;
2639 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
2640 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
2641 ++aPredIter, ++aBinaryIter )
2643 int aCurrBinary = *aBinaryIter;
2645 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
2647 if ( aPrevBinary == SMESH::FT_LogicalAND )
2650 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2651 aBinaryPred->SetPredicate1( aPrevPredicate );
2652 aBinaryPred->SetPredicate2( *aPredIter );
2653 aCurrPred = aBinaryPred;
2656 aCurrPred = *aPredIter;
2658 if ( aCurrBinary != SMESH::FT_LogicalAND )
2659 aResList.push_back( aCurrPred );
2661 aPrevPredicate = aCurrPred;
2662 aPrevBinary = aCurrBinary;
2665 // combine all "OR" operations
2667 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2669 if ( aResList.size() == 1 )
2670 aResPredicate = *aResList.begin();
2671 else if ( aResList.size() > 1 )
2673 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2674 aResPredicate = *anIter;
2676 for ( ; anIter != aResList.end(); ++anIter )
2678 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2679 aBinaryPred->SetPredicate1( aResPredicate );
2680 aBinaryPred->SetPredicate2( *anIter );
2681 aResPredicate = aBinaryPred;
2685 SetPredicate( aResPredicate );
2687 return !aResPredicate->_is_nil();
2690 //=======================================================================
2691 // name : Filter_i::GetPredicate_i
2692 // Purpose : Get implementation of predicate
2693 //=======================================================================
2694 Predicate_i* Filter_i::GetPredicate_i()
2699 //=======================================================================
2700 // name : Filter_i::GetPredicate
2701 // Purpose : Get predicate
2702 //=======================================================================
2703 Predicate_ptr Filter_i::GetPredicate()
2705 if ( myPredicate == 0 )
2706 return SMESH::Predicate::_nil();
2709 SMESH::Predicate_var anObj = myPredicate->_this();
2710 return anObj._retn();
2718 #define ATTR_TYPE "type"
2719 #define ATTR_COMPARE "compare"
2720 #define ATTR_THRESHOLD "threshold"
2721 #define ATTR_UNARY "unary"
2722 #define ATTR_BINARY "binary"
2723 #define ATTR_THRESHOLD_STR "threshold_str"
2724 #define ATTR_TOLERANCE "tolerance"
2725 #define ATTR_ELEMENT_TYPE "ElementType"
2727 //=======================================================================
2729 // Purpose : Convert bool to LDOMString
2730 //=======================================================================
2731 static inline LDOMString toString( CORBA::Boolean val )
2733 return val ? "logical not" : "";
2736 //=======================================================================
2738 // Purpose : Convert LDOMString to bool
2739 //=======================================================================
2740 static inline bool toBool( const LDOMString& theStr )
2742 return theStr.equals( "logical not" );
2745 //=======================================================================
2747 // Purpose : Convert double to LDOMString
2748 //=======================================================================
2749 static inline LDOMString toString( CORBA::Double val )
2752 sprintf( a, "%e", val );
2753 return LDOMString( a );
2756 //=======================================================================
2758 // Purpose : Convert LDOMString to double
2759 //=======================================================================
2760 static inline double toDouble( const LDOMString& theStr )
2762 return atof( theStr.GetString() );
2765 //=======================================================================
2767 // Purpose : Convert functor type to LDOMString
2768 //=======================================================================
2769 static inline LDOMString toString( CORBA::Long theType )
2773 case FT_AspectRatio : return "Aspect ratio";
2774 case FT_Warping : return "Warping";
2775 case FT_MinimumAngle : return "Minimum angle";
2776 case FT_Taper : return "Taper";
2777 case FT_Skew : return "Skew";
2778 case FT_Area : return "Area";
2779 case FT_Volume3D : return "Volume3D";
2780 case FT_BelongToGeom : return "Belong to Geom";
2781 case FT_BelongToPlane : return "Belong to Plane";
2782 case FT_BelongToCylinder: return "Belong to Cylinder";
2783 case FT_BelongToGenSurface: return "Belong to Generic Surface";
2784 case FT_LyingOnGeom : return "Lying on Geom";
2785 case FT_BadOrientedVolume: return "Bad Oriented Volume";
2786 case FT_RangeOfIds : return "Range of IDs";
2787 case FT_FreeBorders : return "Free borders";
2788 case FT_FreeEdges : return "Free edges";
2789 case FT_FreeFaces : return "Free faces";
2790 case FT_FreeNodes : return "Free nodes";
2791 case FT_MultiConnection : return "Borders at multi-connections";
2792 case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2793 case FT_Length : return "Length";
2794 case FT_Length2D : return "Length 2D";
2795 case FT_LessThan : return "Less than";
2796 case FT_MoreThan : return "More than";
2797 case FT_EqualTo : return "Equal to";
2798 case FT_LogicalNOT : return "Not";
2799 case FT_LogicalAND : return "And";
2800 case FT_LogicalOR : return "Or";
2801 case FT_GroupColor : return "Color of Group";
2802 case FT_LinearOrQuadratic : return "Linear or Quadratic";
2803 case FT_ElemGeomType : return "Element geomtry type";
2804 case FT_Undefined : return "";
2805 default : return "";
2809 //=======================================================================
2810 // name : toFunctorType
2811 // Purpose : Convert LDOMString to functor type
2812 //=======================================================================
2813 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
2815 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
2816 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
2817 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
2818 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
2819 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
2820 else if ( theStr.equals( "Area" ) ) return FT_Area;
2821 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
2822 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
2823 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
2824 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
2825 else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface;
2826 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
2827 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
2828 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
2829 else if ( theStr.equals( "Free faces" ) ) return FT_FreeFaces;
2830 else if ( theStr.equals( "Free nodes" ) ) return FT_FreeNodes;
2831 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
2832 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
2833 else if ( theStr.equals( "Length" ) ) return FT_Length;
2834 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
2835 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
2836 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
2837 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
2838 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
2839 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
2840 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
2841 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
2842 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
2843 else if ( theStr.equals( "Color of Group" ) ) return FT_GroupColor;
2844 else if ( theStr.equals( "Linear or Quadratic" ) ) return FT_LinearOrQuadratic;
2845 else if ( theStr.equals( "Element geomtry type" ) ) return FT_ElemGeomType;
2846 else if ( theStr.equals( "" ) ) return FT_Undefined;
2847 else return FT_Undefined;
2850 //=======================================================================
2851 // name : toFunctorType
2852 // Purpose : Convert LDOMString to value of ElementType enumeration
2853 //=======================================================================
2854 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
2856 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
2857 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
2858 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
2859 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
2860 else return SMESH::ALL;
2863 //=======================================================================
2865 // Purpose : Convert ElementType to string
2866 //=======================================================================
2867 static inline LDOMString toString( const SMESH::ElementType theType )
2871 case SMESH::NODE : return "NODE";
2872 case SMESH::EDGE : return "EDGE";
2873 case SMESH::FACE : return "FACE";
2874 case SMESH::VOLUME : return "VOLUME";
2875 case SMESH::ALL : return "ALL";
2876 default : return "";
2880 //=======================================================================
2881 // name : findFilter
2882 // Purpose : Find filter in document
2883 //=======================================================================
2884 static LDOM_Element findFilter( const char* theFilterName,
2885 const LDOM_Document& theDoc,
2886 LDOM_Node* theParent = 0 )
2888 LDOM_Element aRootElement = theDoc.getDocumentElement();
2889 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
2890 return LDOM_Element();
2892 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
2893 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
2895 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
2896 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2898 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
2899 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
2900 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
2902 if ( theParent != 0 )
2903 *theParent = aTypeNode;
2904 return (LDOM_Element&)aFilter;
2908 return LDOM_Element();
2911 //=======================================================================
2912 // name : getSectionName
2913 // Purpose : Get name of section of filters
2914 //=======================================================================
2915 static const char* getSectionName( const ElementType theType )
2919 case SMESH::NODE : return "Filters for nodes";
2920 case SMESH::EDGE : return "Filters for edges";
2921 case SMESH::FACE : return "Filters for faces";
2922 case SMESH::VOLUME : return "Filters for volumes";
2923 case SMESH::ALL : return "Filters for elements";
2924 default : return "";
2928 //=======================================================================
2929 // name : getSection
2930 // Purpose : Create section for filters corresponding to the entity type
2931 //=======================================================================
2932 static LDOM_Node getSection( const ElementType theType,
2933 LDOM_Document& theDoc,
2934 const bool toCreate = false )
2936 LDOM_Element aRootElement = theDoc.getDocumentElement();
2937 if ( aRootElement.isNull() )
2941 bool anExist = false;
2942 const char* aSectionName = getSectionName( theType );
2943 if ( strcmp( aSectionName, "" ) == 0 )
2946 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
2948 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
2950 aNode = aSections.item( i );
2951 LDOM_Element& anItem = ( LDOM_Element& )aNode;
2952 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
2959 // Create new section if necessary
2964 LDOM_Element aNewItem = theDoc.createElement( "section" );
2965 aNewItem.setAttribute( "name", aSectionName );
2966 aRootElement.appendChild( aNewItem );
2976 //=======================================================================
2977 // name : createFilterItem
2978 // Purpose : Create filter item or LDOM document
2979 //=======================================================================
2980 static LDOM_Element createFilterItem( const char* theName,
2981 SMESH::Filter_ptr theFilter,
2982 LDOM_Document& theDoc )
2984 // create new filter in document
2985 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
2986 aFilterItem.setAttribute( "name", theName );
2988 // save filter criterions
2989 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2991 if ( !theFilter->GetCriteria( aCriteria ) )
2992 return LDOM_Element();
2994 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
2996 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
2998 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
2999 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
3000 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
3001 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
3002 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
3004 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
3005 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
3006 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
3007 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
3009 aFilterItem.appendChild( aCriterionItem );
3015 //=======================================================================
3016 // name : FilterLibrary_i::FilterLibrary_i
3017 // Purpose : Constructor
3018 //=======================================================================
3019 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
3021 myFileName = strdup( theFileName );
3022 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
3023 myFilterMgr = aFilterMgr->_this();
3027 // Try to use existing library file
3028 bool anExists = false;
3029 if ( !aParser.parse( myFileName ) )
3031 myDoc = aParser.getDocument();
3034 // Create a new XML document if it doesn't exist
3036 myDoc = LDOM_Document::createDocument( LDOMString() );
3038 LDOM_Element aRootElement = myDoc.getDocumentElement();
3039 if ( aRootElement.isNull() )
3041 // If the existing document is empty --> try to create a new one
3043 myDoc = LDOM_Document::createDocument( LDOMString() );
3047 //=======================================================================
3048 // name : FilterLibrary_i::FilterLibrary_i
3049 // Purpose : Constructor
3050 //=======================================================================
3051 FilterLibrary_i::FilterLibrary_i()
3054 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
3055 myFilterMgr = aFilter->_this();
3057 myDoc = LDOM_Document::createDocument( LDOMString() );
3060 FilterLibrary_i::~FilterLibrary_i()
3063 //TPythonDump()<<this<<".Destroy()";
3066 //=======================================================================
3067 // name : FilterLibrary_i::Copy
3068 // Purpose : Create filter and initialize it with values from library
3069 //=======================================================================
3070 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
3072 Filter_ptr aRes = Filter::_nil();
3073 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
3075 if ( aFilter.isNull() )
3078 std::list<SMESH::Filter::Criterion> aCriteria;
3080 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
3081 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
3083 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
3085 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
3086 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
3087 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
3088 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
3089 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
3091 SMESH::Filter::Criterion aCriterion = createCriterion();
3093 aCriterion.Type = toFunctorType( aTypeStr );
3094 aCriterion.Compare = toFunctorType( aCompareStr );
3095 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
3096 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
3098 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
3100 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
3102 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3103 ? val : atof( str.GetString() );
3105 str = aCrit->getAttribute( ATTR_TOLERANCE );
3106 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3107 ? val : atof( str.GetString() );
3109 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
3110 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
3113 sprintf( a, "%d", val );
3114 aCriterion.ThresholdStr = strdup( a );
3117 aCriterion.ThresholdStr = str.GetString();
3119 aCriteria.push_back( aCriterion );
3122 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
3123 aCriteriaVar->length( aCriteria.size() );
3126 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
3128 for( ; anIter != aCriteria.end(); ++anIter )
3129 aCriteriaVar[ i++ ] = *anIter;
3131 aRes = myFilterMgr->CreateFilter();
3132 aRes->SetCriteria( aCriteriaVar.inout() );
3134 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
3139 //=======================================================================
3140 // name : FilterLibrary_i::SetFileName
3141 // Purpose : Set file name for library
3142 //=======================================================================
3143 void FilterLibrary_i::SetFileName( const char* theFileName )
3146 myFileName = strdup( theFileName );
3147 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
3150 //=======================================================================
3151 // name : FilterLibrary_i::GetFileName
3152 // Purpose : Get file name of library
3153 //=======================================================================
3154 char* FilterLibrary_i::GetFileName()
3156 return CORBA::string_dup( myFileName );
3159 //=======================================================================
3160 // name : FilterLibrary_i::Add
3161 // Purpose : Add new filter to library
3162 //=======================================================================
3163 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
3165 // if filter already in library or entry filter is null do nothing
3166 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3167 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
3170 // get section corresponding to the filter type
3171 ElementType anEntType = theFilter->GetElementType();
3173 LDOM_Node aSection = getSection( anEntType, myDoc, true );
3174 if ( aSection.isNull() )
3177 // create filter item
3178 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
3179 if ( aFilterItem.isNull() )
3183 aSection.appendChild( aFilterItem );
3184 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3185 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
3190 //=======================================================================
3191 // name : FilterLibrary_i::Add
3192 // Purpose : Add new filter to library
3193 //=======================================================================
3194 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
3196 // if filter already in library or entry filter is null do nothing
3197 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3198 if ( !aFilterNode.isNull() )
3201 LDOM_Node aSection = getSection( theType, myDoc, true );
3202 if ( aSection.isNull() )
3205 // create filter item
3206 Filter_var aFilter = myFilterMgr->CreateFilter();
3208 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
3209 if ( aFilterItem.isNull() )
3213 aSection.appendChild( aFilterItem );
3214 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
3219 //=======================================================================
3220 // name : FilterLibrary_i::Delete
3221 // Purpose : Delete filter from library
3222 //=======================================================================
3223 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
3225 LDOM_Node aParentNode;
3226 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
3227 if ( aFilterNode.isNull() || aParentNode.isNull() )
3230 aParentNode.removeChild( aFilterNode );
3231 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
3235 //=======================================================================
3236 // name : FilterLibrary_i::Replace
3237 // Purpose : Replace existing filter with entry filter.
3238 // IMPORTANT : If filter does not exist it is not created
3239 //=======================================================================
3240 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
3241 const char* theNewName,
3242 Filter_ptr theFilter )
3244 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
3245 if ( aFilterItem.isNull() || theFilter->_is_nil() )
3248 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
3249 if ( aNewItem.isNull() )
3253 aFilterItem.ReplaceElement( aNewItem );
3254 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3255 TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
3260 //=======================================================================
3261 // name : FilterLibrary_i::Save
3262 // Purpose : Save library on disk
3263 //=======================================================================
3264 CORBA::Boolean FilterLibrary_i::Save()
3266 if ( myFileName == 0 || strlen( myFileName ) == 0 )
3269 FILE* aOutFile = fopen( myFileName, "wt" );
3273 LDOM_XmlWriter aWriter( aOutFile );
3274 aWriter.SetIndentation( 2 );
3278 TPythonDump()<<this<<".Save()";
3282 //=======================================================================
3283 // name : FilterLibrary_i::SaveAs
3284 // Purpose : Save library on disk
3285 //=======================================================================
3286 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
3288 myFileName = strdup ( aFileName );
3289 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
3293 //=======================================================================
3294 // name : FilterLibrary_i::IsPresent
3295 // Purpose : Verify whether filter is in library
3296 //=======================================================================
3297 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
3299 return !findFilter( theFilterName, myDoc ).isNull();
3302 //=======================================================================
3303 // name : FilterLibrary_i::NbFilters
3304 // Purpose : Return amount of filters in library
3305 //=======================================================================
3306 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
3308 string_array_var aNames = GetNames( theType );
3309 return aNames->length();
3312 //=======================================================================
3313 // name : FilterLibrary_i::GetNames
3314 // Purpose : Get names of filters from library
3315 //=======================================================================
3316 string_array* FilterLibrary_i::GetNames( ElementType theType )
3318 string_array_var anArray = new string_array;
3319 TColStd_SequenceOfHAsciiString aSeq;
3321 LDOM_Node aSection = getSection( theType, myDoc, false );
3323 if ( !aSection.isNull() )
3325 for ( LDOM_Node aFilter = aSection.getFirstChild();
3326 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3328 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
3329 aSeq.Append( new TCollection_HAsciiString(
3330 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
3334 anArray->length( aSeq.Length() );
3335 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
3336 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
3338 return anArray._retn();
3341 //=======================================================================
3342 // name : FilterLibrary_i::GetAllNames
3343 // Purpose : Get names of filters from library
3344 //=======================================================================
3345 string_array* FilterLibrary_i::GetAllNames()
3347 string_array_var aResArray = new string_array;
3348 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
3350 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
3352 int aPrevLength = aResArray->length();
3353 aResArray->length( aPrevLength + aNames->length() );
3354 for ( int i = 0, n = aNames->length(); i < n; i++ )
3355 aResArray[ aPrevLength + i ] = aNames[ i ];
3358 return aResArray._retn();