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"
36 #include "SMESHDS_Mesh.hxx"
38 #include <BRep_Tool.hxx>
39 #include <Geom_CylindricalSurface.hxx>
40 #include <Geom_Plane.hxx>
41 #include <LDOMParser.hxx>
42 #include <LDOMString.hxx>
43 #include <LDOM_Document.hxx>
44 #include <LDOM_Element.hxx>
45 #include <LDOM_Node.hxx>
46 #include <LDOM_XmlWriter.hxx>
47 #include <Precision.hxx>
48 #include <TColStd_ListIteratorOfListOfInteger.hxx>
49 #include <TColStd_ListIteratorOfListOfReal.hxx>
50 #include <TColStd_ListOfInteger.hxx>
51 #include <TColStd_ListOfReal.hxx>
52 #include <TColStd_SequenceOfHAsciiString.hxx>
53 #include <TCollection_HAsciiString.hxx>
55 #include <TopExp_Explorer.hxx>
57 #include <TopoDS_Face.hxx>
58 #include <TopoDS_Shape.hxx>
59 #include <TopTools_IndexedMapOfShape.hxx>
61 using namespace SMESH;
62 using namespace SMESH::Controls;
68 GetPredicate( Predicate_ptr thePredicate )
70 return DownCast<Predicate_i*>(thePredicate);
77 Description : Predicate for verifying whether entity belongs to
78 specified geometrical support
81 Controls::BelongToGeom::BelongToGeom()
85 myTolerance(Precision::Confusion())
88 void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
90 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
94 void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
100 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
101 const TopoDS_Shape& theShape)
103 if (theMap.Contains(theShape)) return true;
105 if (theShape.ShapeType() == TopAbs_COMPOUND ||
106 theShape.ShapeType() == TopAbs_COMPSOLID)
108 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
109 for (; anIt.More(); anIt.Next())
111 if (!IsSubShape(theMap, anIt.Value())) {
121 void Controls::BelongToGeom::init()
123 if (!myMeshDS || myShape.IsNull()) return;
125 // is subshape of main shape?
126 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
127 if (aMainShape.IsNull()) {
128 myIsSubshape = false;
131 TopTools_IndexedMapOfShape aMap;
132 TopExp::MapShapes(aMainShape, aMap);
133 myIsSubshape = IsSubShape(aMap, myShape);
138 myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
139 myElementsOnShapePtr->SetTolerance(myTolerance);
140 myElementsOnShapePtr->SetAllNodes(true); // belong, while false means "lays on"
141 myElementsOnShapePtr->SetMesh(myMeshDS);
142 myElementsOnShapePtr->SetShape(myShape, myType);
146 static bool IsContains( const SMESHDS_Mesh* theMeshDS,
147 const TopoDS_Shape& theShape,
148 const SMDS_MeshElement* theElem,
149 TopAbs_ShapeEnum theFindShapeEnum,
150 TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE )
152 TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
154 while( anExp.More() )
156 const TopoDS_Shape& aShape = anExp.Current();
157 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
158 if( aSubMesh->Contains( theElem ) )
166 bool Controls::BelongToGeom::IsSatisfy (long theId)
168 if (myMeshDS == 0 || myShape.IsNull())
173 return myElementsOnShapePtr->IsSatisfy(theId);
177 if (myType == SMDSAbs_Node)
179 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
181 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
182 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
183 switch( aTypeOfPosition )
185 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
186 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
187 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
188 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
194 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
196 if( myType == SMDSAbs_All )
198 return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
199 IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
200 IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
201 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
203 else if( myType == anElem->GetType() )
207 case SMDSAbs_Edge : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
208 case SMDSAbs_Face : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
209 case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
210 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
219 void Controls::BelongToGeom::SetType (SMDSAbs_ElementType theType)
225 SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
230 TopoDS_Shape Controls::BelongToGeom::GetShape()
235 const SMESHDS_Mesh* Controls::BelongToGeom::GetMeshDS() const
240 void Controls::BelongToGeom::SetTolerance (double theTolerance)
242 myTolerance = theTolerance;
247 double Controls::BelongToGeom::GetTolerance()
254 Description : Predicate for verifying whether entiy lying or partially lying on
255 specified geometrical support
258 Controls::LyingOnGeom::LyingOnGeom()
262 myTolerance(Precision::Confusion())
265 void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
267 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
271 void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
277 void Controls::LyingOnGeom::init()
279 if (!myMeshDS || myShape.IsNull()) return;
281 // is subshape of main shape?
282 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
283 if (aMainShape.IsNull()) {
284 myIsSubshape = false;
287 TopTools_IndexedMapOfShape aMap;
288 TopExp::MapShapes(aMainShape, aMap);
289 myIsSubshape = IsSubShape(aMap, myShape);
294 myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
295 myElementsOnShapePtr->SetTolerance(myTolerance);
296 myElementsOnShapePtr->SetAllNodes(false); // lays on, while true means "belong"
297 myElementsOnShapePtr->SetMesh(myMeshDS);
298 myElementsOnShapePtr->SetShape(myShape, myType);
302 bool Controls::LyingOnGeom::IsSatisfy( long theId )
304 if ( myMeshDS == 0 || myShape.IsNull() )
309 return myElementsOnShapePtr->IsSatisfy(theId);
313 if( myType == SMDSAbs_Node )
315 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
317 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
318 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
319 switch( aTypeOfPosition )
321 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
322 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
323 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
324 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
330 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
332 if( myType == SMDSAbs_All )
334 return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
335 Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
336 Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
337 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
339 else if( myType == anElem->GetType() )
343 case SMDSAbs_Edge : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
344 case SMDSAbs_Face : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
345 case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
346 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
355 void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
361 SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
366 TopoDS_Shape Controls::LyingOnGeom::GetShape()
371 const SMESHDS_Mesh* Controls::LyingOnGeom::GetMeshDS() const
376 void Controls::LyingOnGeom::SetTolerance (double theTolerance)
378 myTolerance = theTolerance;
383 double Controls::LyingOnGeom::GetTolerance()
388 bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh* theMeshDS,
389 const TopoDS_Shape& theShape,
390 const SMDS_MeshElement* theElem,
391 TopAbs_ShapeEnum theFindShapeEnum,
392 TopAbs_ShapeEnum theAvoidShapeEnum )
394 if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
397 TopTools_IndexedMapOfShape aSubShapes;
398 TopExp::MapShapes( theShape, aSubShapes );
400 for (int i = 1; i <= aSubShapes.Extent(); i++)
402 const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
404 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
405 if( aSubMesh->Contains( theElem ) )
408 SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
409 while ( aNodeIt->more() )
411 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
412 SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
413 while ( anElemIt->more() )
415 const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
416 if (anElement == theElem)
432 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
434 SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
435 return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
440 toArray( const TColStd_ListOfInteger& aList )
442 SMESH::long_array_var anArray = new SMESH::long_array;
443 anArray->length( aList.Extent() );
444 TColStd_ListIteratorOfListOfInteger anIter( aList );
446 for( ; anIter.More(); anIter.Next() )
447 anArray[ i++ ] = anIter.Value();
449 return anArray._retn();
454 toArray( const TColStd_ListOfReal& aList )
456 SMESH::double_array_var anArray = new SMESH::double_array;
457 anArray->length( aList.Extent() );
458 TColStd_ListIteratorOfListOfReal anIter( aList );
460 for( ; anIter.More(); anIter.Next() )
461 anArray[ i++ ] = anIter.Value();
463 return anArray._retn();
466 static SMESH::Filter::Criterion createCriterion()
468 SMESH::Filter::Criterion aCriterion;
470 aCriterion.Type = FT_Undefined;
471 aCriterion.Compare = FT_Undefined;
472 aCriterion.Threshold = 0;
473 aCriterion.UnaryOp = FT_Undefined;
474 aCriterion.BinaryOp = FT_Undefined;
475 aCriterion.ThresholdStr = "";
476 aCriterion.ThresholdID = "";
477 aCriterion.Tolerance = Precision::Confusion();
478 aCriterion.TypeOfElement = SMESH::ALL;
479 aCriterion.Precision = -1;
484 static TopoDS_Shape getShapeByName( const char* theName )
488 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
489 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
490 if (!CORBA::is_nil(aStudy))
492 SALOMEDS::Study::ListOfSObject_var aList =
493 aStudy->FindObjectByName( theName, "GEOM" );
494 if ( aList->length() > 0 )
496 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
497 if ( !aGeomObj->_is_nil() )
499 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
500 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
506 return TopoDS_Shape();
509 static TopoDS_Shape getShapeByID (const char* theID)
511 if (theID != 0 && theID != "") {
512 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
513 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
515 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
516 SALOMEDS::GenericAttribute_var anAttr;
517 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
518 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
519 CORBA::String_var aVal = anIOR->Value();
520 CORBA::Object_var obj = aStudy->ConvertIORToObject(aVal);
521 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
523 if (!aGeomObj->_is_nil()) {
524 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
525 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
531 return TopoDS_Shape();
534 static char* getShapeNameByID (const char* theID)
538 if (theID != 0 && theID != "") {
539 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
540 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
542 //SALOMEDS::SObject_var aSObj = aStudy->FindObjectIOR( theID );
543 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
544 SALOMEDS::GenericAttribute_var anAttr;
545 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeName")) {
546 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
547 aName = aNameAttr->Value();
561 Description : An abstact class for all functors
563 Functor_i::Functor_i():
564 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
566 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
567 //PortableServer::ObjectId_var anObjectId =
568 // SMESH_Gen_i::GetPOA()->activate_object( this );
571 Functor_i::~Functor_i()
573 //TPythonDump()<<this<<".Destroy()";
576 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
578 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
579 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
582 ElementType Functor_i::GetElementType()
584 return ( ElementType )myFunctorPtr->GetType();
589 Class : NumericalFunctor_i
590 Description : Base class for numerical functors
592 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
594 return myNumericalFunctorPtr->GetValue( theId );
597 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
599 myNumericalFunctorPtr->SetPrecision( thePrecision );
600 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
603 CORBA::Long NumericalFunctor_i::GetPrecision()
605 return myNumericalFunctorPtr->GetPrecision();
608 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
610 return myNumericalFunctorPtr;
615 Class : SMESH_MinimumAngle
616 Description : Functor for calculation of minimum angle
618 MinimumAngle_i::MinimumAngle_i()
620 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
621 myFunctorPtr = myNumericalFunctorPtr;
624 FunctorType MinimumAngle_i::GetFunctorType()
626 return SMESH::FT_MinimumAngle;
632 Description : Functor for calculating aspect ratio
634 AspectRatio_i::AspectRatio_i()
636 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
637 myFunctorPtr = myNumericalFunctorPtr;
640 FunctorType AspectRatio_i::GetFunctorType()
642 return SMESH::FT_AspectRatio;
647 Class : AspectRatio3D
648 Description : Functor for calculating aspect ratio 3D
650 AspectRatio3D_i::AspectRatio3D_i()
652 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
653 myFunctorPtr = myNumericalFunctorPtr;
656 FunctorType AspectRatio3D_i::GetFunctorType()
658 return SMESH::FT_AspectRatio3D;
664 Description : Functor for calculating warping
666 Warping_i::Warping_i()
668 myNumericalFunctorPtr.reset( new Controls::Warping() );
669 myFunctorPtr = myNumericalFunctorPtr;
672 FunctorType Warping_i::GetFunctorType()
674 return SMESH::FT_Warping;
680 Description : Functor for calculating taper
684 myNumericalFunctorPtr.reset( new Controls::Taper() );
685 myFunctorPtr = myNumericalFunctorPtr;
688 FunctorType Taper_i::GetFunctorType()
690 return SMESH::FT_Taper;
696 Description : Functor for calculating skew in degrees
700 myNumericalFunctorPtr.reset( new Controls::Skew() );
701 myFunctorPtr = myNumericalFunctorPtr;
704 FunctorType Skew_i::GetFunctorType()
706 return SMESH::FT_Skew;
711 Description : Functor for calculating area
715 myNumericalFunctorPtr.reset( new Controls::Area() );
716 myFunctorPtr = myNumericalFunctorPtr;
719 FunctorType Area_i::GetFunctorType()
721 return SMESH::FT_Area;
726 Description : Functor for calculating volume of 3D element
728 Volume3D_i::Volume3D_i()
730 myNumericalFunctorPtr.reset( new Controls::Volume() );
731 myFunctorPtr = myNumericalFunctorPtr;
734 FunctorType Volume3D_i::GetFunctorType()
736 return SMESH::FT_Volume3D;
741 Description : Functor for calculating length off edge
745 myNumericalFunctorPtr.reset( new Controls::Length() );
746 myFunctorPtr = myNumericalFunctorPtr;
749 FunctorType Length_i::GetFunctorType()
751 return SMESH::FT_Length;
756 Description : Functor for calculating length of edge
758 Length2D_i::Length2D_i()
760 myNumericalFunctorPtr.reset( new Controls::Length2D() );
761 myFunctorPtr = myNumericalFunctorPtr;
764 FunctorType Length2D_i::GetFunctorType()
766 return SMESH::FT_Length2D;
769 SMESH::Length2D::Values* Length2D_i::GetValues()
771 INFOS("Length2D_i::GetValues");
772 SMESH::Controls::Length2D::TValues aValues;
773 myLength2DPtr->GetValues( aValues );
775 long i = 0, iEnd = aValues.size();
777 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
779 SMESH::Controls::Length2D::TValues::const_iterator anIter;
780 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
782 const SMESH::Controls::Length2D::Value& aVal = *anIter;
783 SMESH::Length2D::Value &aValue = aResult[ i ];
785 aValue.myLength = aVal.myLength;
786 aValue.myPnt1 = aVal.myPntId[ 0 ];
787 aValue.myPnt2 = aVal.myPntId[ 1 ];
790 INFOS("Length2D_i::GetValuess~");
791 return aResult._retn();
795 Class : MultiConnection_i
796 Description : Functor for calculating number of faces conneted to the edge
798 MultiConnection_i::MultiConnection_i()
800 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
801 myFunctorPtr = myNumericalFunctorPtr;
804 FunctorType MultiConnection_i::GetFunctorType()
806 return SMESH::FT_MultiConnection;
810 Class : MultiConnection2D_i
811 Description : Functor for calculating number of faces conneted to the edge
813 MultiConnection2D_i::MultiConnection2D_i()
815 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
816 myFunctorPtr = myNumericalFunctorPtr;
819 FunctorType MultiConnection2D_i::GetFunctorType()
821 return SMESH::FT_MultiConnection2D;
824 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
826 INFOS("MultiConnection2D_i::GetValues");
827 SMESH::Controls::MultiConnection2D::MValues aValues;
828 myMulticonnection2DPtr->GetValues( aValues );
830 long i = 0, iEnd = aValues.size();
832 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
834 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
835 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
837 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
838 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
840 aValue.myPnt1 = aVal.myPntId[ 0 ];
841 aValue.myPnt2 = aVal.myPntId[ 1 ];
842 aValue.myNbConnects = (*anIter).second;
845 INFOS("Multiconnection2D_i::GetValuess~");
846 return aResult._retn();
856 Description : Base class for all predicates
858 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
860 return myPredicatePtr->IsSatisfy( theId );
863 Controls::PredicatePtr Predicate_i::GetPredicate()
865 return myPredicatePtr;
869 Class : BadOrientedVolume_i
870 Description : Verify whether a mesh volume is incorrectly oriented from
871 the point of view of MED convention
873 BadOrientedVolume_i::BadOrientedVolume_i()
875 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
876 myFunctorPtr = myPredicatePtr = control;
879 FunctorType BadOrientedVolume_i::GetFunctorType()
881 return SMESH::FT_BadOrientedVolume;
885 Class : BelongToGeom_i
886 Description : Predicate for selection on geometrical support
888 BelongToGeom_i::BelongToGeom_i()
890 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
891 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
896 BelongToGeom_i::~BelongToGeom_i()
902 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
904 if ( theGeom->_is_nil() )
906 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
907 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
908 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
909 myBelongToGeomPtr->SetGeom( aLocShape );
910 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
913 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
915 myBelongToGeomPtr->SetGeom( theShape );
918 void BelongToGeom_i::SetElementType(ElementType theType){
919 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
920 TPythonDump()<<this<<".SetElementType("<<theType<<")";
923 FunctorType BelongToGeom_i::GetFunctorType()
925 return SMESH::FT_BelongToGeom;
928 void BelongToGeom_i::SetShapeName( const char* theName )
931 myShapeName = strdup( theName );
932 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
933 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
936 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
939 myShapeName = strdup( theName );
942 myShapeID = strdup( theID );
946 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
947 myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
949 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
952 char* BelongToGeom_i::GetShapeName()
954 return CORBA::string_dup( myShapeName );
957 char* BelongToGeom_i::GetShapeID()
959 return CORBA::string_dup( myShapeID );
962 void BelongToGeom_i::SetTolerance( CORBA::Double theToler )
964 myBelongToGeomPtr->SetTolerance( theToler );
965 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
968 CORBA::Double BelongToGeom_i::GetTolerance()
970 return myBelongToGeomPtr->GetTolerance();
974 Class : BelongToSurface_i
975 Description : Predicate for selection on geometrical support
977 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
979 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
980 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
983 mySurfaceType = theSurfaceType;
986 BelongToSurface_i::~BelongToSurface_i()
992 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
994 if ( theGeom->_is_nil() )
996 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
997 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
998 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1000 if ( aLocShape.ShapeType() == TopAbs_FACE )
1002 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
1003 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
1005 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1010 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
1013 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
1016 myShapeName = strdup( theName );
1017 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1018 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
1021 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
1024 myShapeName = strdup( theName );
1027 myShapeID = strdup( theID );
1031 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1032 myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
1034 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1037 char* BelongToSurface_i::GetShapeName()
1039 return CORBA::string_dup( myShapeName );
1042 char* BelongToSurface_i::GetShapeID()
1044 return CORBA::string_dup( myShapeID );
1047 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
1049 myElementsOnSurfacePtr->SetTolerance( theToler );
1050 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1053 CORBA::Double BelongToSurface_i::GetTolerance()
1055 return myElementsOnSurfacePtr->GetTolerance();
1058 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
1060 myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
1061 TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
1064 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
1066 return myElementsOnSurfacePtr->GetUseBoundaries();
1071 Class : BelongToPlane_i
1072 Description : Verify whether mesh element lie in pointed Geom planar object
1075 BelongToPlane_i::BelongToPlane_i()
1076 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
1080 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1082 BelongToSurface_i::SetSurface( theGeom, theType );
1083 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
1086 FunctorType BelongToPlane_i::GetFunctorType()
1088 return FT_BelongToPlane;
1092 Class : BelongToCylinder_i
1093 Description : Verify whether mesh element lie in pointed Geom planar object
1096 BelongToCylinder_i::BelongToCylinder_i()
1097 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1101 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1103 BelongToSurface_i::SetSurface( theGeom, theType );
1104 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
1107 FunctorType BelongToCylinder_i::GetFunctorType()
1109 return FT_BelongToCylinder;
1113 Class : BelongToGenSurface_i
1114 Description : Verify whether mesh element lie in pointed Geom planar object
1117 BelongToGenSurface_i::BelongToGenSurface_i()
1118 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1122 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1124 if ( theGeom->_is_nil() )
1126 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1127 if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1128 aLocShape.Nullify();
1130 BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1131 TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1134 FunctorType BelongToGenSurface_i::GetFunctorType()
1136 return FT_BelongToGenSurface;
1140 Class : LyingOnGeom_i
1141 Description : Predicate for selection on geometrical support
1143 LyingOnGeom_i::LyingOnGeom_i()
1145 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1146 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1151 LyingOnGeom_i::~LyingOnGeom_i()
1157 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1159 if ( theGeom->_is_nil() )
1161 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1162 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1163 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1164 myLyingOnGeomPtr->SetGeom( aLocShape );
1165 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1168 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1170 myLyingOnGeomPtr->SetGeom( theShape );
1173 void LyingOnGeom_i::SetElementType(ElementType theType){
1174 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1175 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1178 FunctorType LyingOnGeom_i::GetFunctorType()
1180 return SMESH::FT_LyingOnGeom;
1183 void LyingOnGeom_i::SetShapeName( const char* theName )
1186 myShapeName = strdup( theName );
1187 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1188 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1191 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1194 myShapeName = strdup( theName );
1197 myShapeID = strdup( theID );
1201 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1202 myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
1204 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1207 char* LyingOnGeom_i::GetShapeName()
1209 return CORBA::string_dup( myShapeName );
1212 char* LyingOnGeom_i::GetShapeID()
1214 return CORBA::string_dup( myShapeID );
1217 void LyingOnGeom_i::SetTolerance( CORBA::Double theToler )
1219 myLyingOnGeomPtr->SetTolerance( theToler );
1220 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1223 CORBA::Double LyingOnGeom_i::GetTolerance()
1225 return myLyingOnGeomPtr->GetTolerance();
1229 Class : FreeBorders_i
1230 Description : Predicate for free borders
1232 FreeBorders_i::FreeBorders_i()
1234 myPredicatePtr.reset(new Controls::FreeBorders());
1235 myFunctorPtr = myPredicatePtr;
1238 FunctorType FreeBorders_i::GetFunctorType()
1240 return SMESH::FT_FreeBorders;
1245 Description : Predicate for free borders
1247 FreeEdges_i::FreeEdges_i()
1248 : myFreeEdgesPtr( new Controls::FreeEdges() )
1250 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1253 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1255 INFOS("FreeEdges_i::GetBorders");
1256 SMESH::Controls::FreeEdges::TBorders aBorders;
1257 myFreeEdgesPtr->GetBoreders( aBorders );
1259 long i = 0, iEnd = aBorders.size();
1261 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1262 aResult->length(iEnd);
1264 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1265 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1267 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1268 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1270 aBorder.myElemId = aBord.myElemId;
1271 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1272 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1275 INFOS("FreeEdges_i::GetBorders~");
1276 return aResult._retn();
1279 FunctorType FreeEdges_i::GetFunctorType()
1281 return SMESH::FT_FreeEdges;
1286 Description : Predicate for free faces
1288 FreeFaces_i::FreeFaces_i()
1290 myPredicatePtr.reset(new Controls::FreeFaces());
1291 myFunctorPtr = myPredicatePtr;
1294 FunctorType FreeFaces_i::GetFunctorType()
1296 return SMESH::FT_FreeFaces;
1301 Description : Predicate for free nodes
1303 FreeNodes_i::FreeNodes_i()
1305 myPredicatePtr.reset(new Controls::FreeNodes());
1306 myFunctorPtr = myPredicatePtr;
1309 FunctorType FreeNodes_i::GetFunctorType()
1311 return SMESH::FT_FreeNodes;
1315 Class : RangeOfIds_i
1316 Description : Predicate for Range of Ids.
1317 Range may be specified with two ways.
1318 1. Using AddToRange method
1319 2. With SetRangeStr method. Parameter of this method is a string
1320 like as "1,2,3,50-60,63,67,70-"
1323 RangeOfIds_i::RangeOfIds_i()
1325 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1326 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1329 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1331 CORBA::Long iEnd = theIds.length();
1332 for ( CORBA::Long i = 0; i < iEnd; i++ )
1333 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1334 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1337 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1339 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1340 return myRangeOfIdsPtr->SetRangeStr(
1341 TCollection_AsciiString( (Standard_CString)theRange ) );
1344 char* RangeOfIds_i::GetRangeStr()
1346 TCollection_AsciiString aStr;
1347 myRangeOfIdsPtr->GetRangeStr( aStr );
1348 return CORBA::string_dup( aStr.ToCString() );
1351 void RangeOfIds_i::SetElementType( ElementType theType )
1353 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1354 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1357 FunctorType RangeOfIds_i::GetFunctorType()
1359 return SMESH::FT_RangeOfIds;
1363 Class : LinearOrQuadratic_i
1364 Description : Predicate to verify whether a mesh element is linear
1366 LinearOrQuadratic_i::LinearOrQuadratic_i()
1368 myLinearOrQuadraticPtr.reset(new Controls::LinearOrQuadratic());
1369 myFunctorPtr = myPredicatePtr = myLinearOrQuadraticPtr;
1372 void LinearOrQuadratic_i::SetElementType(ElementType theType)
1374 myLinearOrQuadraticPtr->SetType(SMDSAbs_ElementType(theType));
1375 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1378 FunctorType LinearOrQuadratic_i::GetFunctorType()
1380 return SMESH::FT_LinearOrQuadratic;
1384 Class : GroupColor_i
1385 Description : Functor for check color of group to whic mesh element belongs to
1387 GroupColor_i::GroupColor_i()
1389 myGroupColorPtr.reset(new Controls::GroupColor());
1390 myFunctorPtr = myPredicatePtr = myGroupColorPtr;
1393 FunctorType GroupColor_i::GetFunctorType()
1395 return SMESH::FT_GroupColor;
1398 void GroupColor_i::SetColorStr( const char* theColor )
1400 myGroupColorPtr->SetColorStr(
1401 TCollection_AsciiString( (Standard_CString)theColor ) );
1402 TPythonDump()<<this<<".SetColorStr('"<<theColor<<"')";
1405 char* GroupColor_i::GetColorStr()
1407 TCollection_AsciiString aStr;
1408 myGroupColorPtr->GetColorStr( aStr );
1409 return CORBA::string_dup( aStr.ToCString() );
1412 void GroupColor_i::SetElementType(ElementType theType)
1414 myGroupColorPtr->SetType(SMDSAbs_ElementType(theType));
1415 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1419 Class : ElemGeomType_i
1420 Description : Predicate check is element has indicated geometry type
1422 ElemGeomType_i::ElemGeomType_i()
1424 myElemGeomTypePtr.reset(new Controls::ElemGeomType());
1425 myFunctorPtr = myPredicatePtr = myElemGeomTypePtr;
1428 void ElemGeomType_i::SetElementType(ElementType theType)
1430 myElemGeomTypePtr->SetType(SMDSAbs_ElementType(theType));
1431 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1434 void ElemGeomType_i::SetGeometryType(GeometryType theType)
1436 myElemGeomTypePtr->SetGeomType(SMDSAbs_GeometryType(theType));
1437 TPythonDump()<<this<<".SetGeometryType("<<theType<<")";
1440 GeometryType ElemGeomType_i::GetGeometryType() const
1442 return (GeometryType)myElemGeomTypePtr->GetGeomType();;
1445 FunctorType ElemGeomType_i::GetFunctorType()
1447 return SMESH::FT_ElemGeomType;
1451 Class : Comparator_i
1452 Description : Base class for comparators
1454 Comparator_i::Comparator_i():
1455 myNumericalFunctor( NULL )
1458 Comparator_i::~Comparator_i()
1460 if ( myNumericalFunctor )
1461 myNumericalFunctor->Destroy();
1464 void Comparator_i::SetMargin( CORBA::Double theValue )
1466 myComparatorPtr->SetMargin( theValue );
1467 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1470 CORBA::Double Comparator_i::GetMargin()
1472 return myComparatorPtr->GetMargin();
1475 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1477 if ( myNumericalFunctor )
1478 myNumericalFunctor->Destroy();
1480 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1482 if ( myNumericalFunctor )
1484 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1485 myNumericalFunctor->Register();
1486 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1490 Controls::ComparatorPtr Comparator_i::GetComparator()
1492 return myComparatorPtr;
1495 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1497 return myNumericalFunctor;
1503 Description : Comparator "<"
1505 LessThan_i::LessThan_i()
1507 myComparatorPtr.reset( new Controls::LessThan() );
1508 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1511 FunctorType LessThan_i::GetFunctorType()
1513 return SMESH::FT_LessThan;
1519 Description : Comparator ">"
1521 MoreThan_i::MoreThan_i()
1523 myComparatorPtr.reset( new Controls::MoreThan() );
1524 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1527 FunctorType MoreThan_i::GetFunctorType()
1529 return SMESH::FT_MoreThan;
1535 Description : Comparator "="
1537 EqualTo_i::EqualTo_i()
1538 : myEqualToPtr( new Controls::EqualTo() )
1540 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1543 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1545 myEqualToPtr->SetTolerance( theToler );
1546 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1549 CORBA::Double EqualTo_i::GetTolerance()
1551 return myEqualToPtr->GetTolerance();
1554 FunctorType EqualTo_i::GetFunctorType()
1556 return SMESH::FT_EqualTo;
1560 Class : LogicalNOT_i
1561 Description : Logical NOT predicate
1563 LogicalNOT_i::LogicalNOT_i()
1564 : myPredicate( NULL ),
1565 myLogicalNOTPtr( new Controls::LogicalNOT() )
1567 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1570 LogicalNOT_i::~LogicalNOT_i()
1573 myPredicate->Destroy();
1576 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1579 myPredicate->Destroy();
1581 myPredicate = SMESH::GetPredicate(thePredicate);
1584 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1585 myPredicate->Register();
1586 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1590 FunctorType LogicalNOT_i::GetFunctorType()
1592 return SMESH::FT_LogicalNOT;
1595 Predicate_i* LogicalNOT_i::GetPredicate_i()
1602 Class : LogicalBinary_i
1603 Description : Base class for binary logical predicate
1605 LogicalBinary_i::LogicalBinary_i()
1606 : myPredicate1( NULL ),
1607 myPredicate2( NULL )
1610 LogicalBinary_i::~LogicalBinary_i()
1613 myPredicate1->Destroy();
1616 myPredicate2->Destroy();
1619 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1622 myPredicate1->SetMesh( theMesh );
1625 myPredicate2->SetMesh( theMesh );
1628 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1631 myPredicate1->Destroy();
1633 myPredicate1 = SMESH::GetPredicate(thePredicate);
1635 if ( myPredicate1 ){
1636 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1637 myPredicate1->Register();
1638 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1642 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1645 myPredicate2->Destroy();
1647 myPredicate2 = SMESH::GetPredicate(thePredicate);
1649 if ( myPredicate2 ){
1650 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1651 myPredicate2->Register();
1652 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1656 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1658 return myLogicalBinaryPtr;
1661 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1663 return myPredicate1;
1665 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1667 return myPredicate2;
1672 Class : LogicalAND_i
1673 Description : Logical AND
1675 LogicalAND_i::LogicalAND_i()
1677 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1678 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1681 FunctorType LogicalAND_i::GetFunctorType()
1683 return SMESH::FT_LogicalAND;
1689 Description : Logical OR
1691 LogicalOR_i::LogicalOR_i()
1693 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1694 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1697 FunctorType LogicalOR_i::GetFunctorType()
1699 return SMESH::FT_LogicalOR;
1707 FilterManager_i::FilterManager_i()
1708 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1710 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
1711 //PortableServer::ObjectId_var anObjectId =
1712 // SMESH_Gen_i::GetPOA()->activate_object( this );
1716 FilterManager_i::~FilterManager_i()
1718 //TPythonDump()<<this<<".Destroy()";
1722 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1724 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1725 SMESH::MinimumAngle_var anObj = aServant->_this();
1726 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1727 return anObj._retn();
1731 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1733 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1734 SMESH::AspectRatio_var anObj = aServant->_this();
1735 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1736 return anObj._retn();
1740 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1742 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1743 SMESH::AspectRatio3D_var anObj = aServant->_this();
1744 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1745 return anObj._retn();
1749 Warping_ptr FilterManager_i::CreateWarping()
1751 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1752 SMESH::Warping_var anObj = aServant->_this();
1753 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1754 return anObj._retn();
1758 Taper_ptr FilterManager_i::CreateTaper()
1760 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1761 SMESH::Taper_var anObj = aServant->_this();
1762 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1763 return anObj._retn();
1767 Skew_ptr FilterManager_i::CreateSkew()
1769 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1770 SMESH::Skew_var anObj = aServant->_this();
1771 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1772 return anObj._retn();
1776 Area_ptr FilterManager_i::CreateArea()
1778 SMESH::Area_i* aServant = new SMESH::Area_i();
1779 SMESH::Area_var anObj = aServant->_this();
1780 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1781 return anObj._retn();
1785 Volume3D_ptr FilterManager_i::CreateVolume3D()
1787 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
1788 SMESH::Volume3D_var anObj = aServant->_this();
1789 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
1790 return anObj._retn();
1794 Length_ptr FilterManager_i::CreateLength()
1796 SMESH::Length_i* aServant = new SMESH::Length_i();
1797 SMESH::Length_var anObj = aServant->_this();
1798 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1799 return anObj._retn();
1802 Length2D_ptr FilterManager_i::CreateLength2D()
1804 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1805 SMESH::Length2D_var anObj = aServant->_this();
1806 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1807 return anObj._retn();
1810 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1812 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1813 SMESH::MultiConnection_var anObj = aServant->_this();
1814 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1815 return anObj._retn();
1818 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1820 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1821 SMESH::MultiConnection2D_var anObj = aServant->_this();
1822 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
1823 return anObj._retn();
1826 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1828 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1829 SMESH::BelongToGeom_var anObj = aServant->_this();
1830 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
1831 return anObj._retn();
1834 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1836 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1837 SMESH::BelongToPlane_var anObj = aServant->_this();
1838 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
1839 return anObj._retn();
1842 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1844 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1845 SMESH::BelongToCylinder_var anObj = aServant->_this();
1846 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
1847 return anObj._retn();
1850 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
1852 SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
1853 SMESH::BelongToGenSurface_var anObj = aServant->_this();
1854 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
1855 return anObj._retn();
1858 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
1860 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
1861 SMESH::LyingOnGeom_var anObj = aServant->_this();
1862 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
1863 return anObj._retn();
1866 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1868 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1869 SMESH::FreeBorders_var anObj = aServant->_this();
1870 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
1871 return anObj._retn();
1874 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1876 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1877 SMESH::FreeEdges_var anObj = aServant->_this();
1878 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
1879 return anObj._retn();
1882 FreeFaces_ptr FilterManager_i::CreateFreeFaces()
1884 SMESH::FreeFaces_i* aServant = new SMESH::FreeFaces_i();
1885 SMESH::FreeFaces_var anObj = aServant->_this();
1886 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeFaces()";
1887 return anObj._retn();
1890 FreeNodes_ptr FilterManager_i::CreateFreeNodes()
1892 SMESH::FreeNodes_i* aServant = new SMESH::FreeNodes_i();
1893 SMESH::FreeNodes_var anObj = aServant->_this();
1894 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeNodes()";
1895 return anObj._retn();
1898 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1900 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1901 SMESH::RangeOfIds_var anObj = aServant->_this();
1902 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
1903 return anObj._retn();
1906 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
1908 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
1909 SMESH::BadOrientedVolume_var anObj = aServant->_this();
1910 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
1911 return anObj._retn();
1914 LessThan_ptr FilterManager_i::CreateLessThan()
1916 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1917 SMESH::LessThan_var anObj = aServant->_this();
1918 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
1919 return anObj._retn();
1922 MoreThan_ptr FilterManager_i::CreateMoreThan()
1924 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1925 SMESH::MoreThan_var anObj = aServant->_this();
1926 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
1927 return anObj._retn();
1930 EqualTo_ptr FilterManager_i::CreateEqualTo()
1932 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1933 SMESH::EqualTo_var anObj = aServant->_this();
1934 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
1935 return anObj._retn();
1938 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1940 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1941 SMESH::LogicalNOT_var anObj = aServant->_this();
1942 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
1943 return anObj._retn();
1946 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
1948 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
1949 SMESH::LogicalAND_var anObj = aServant->_this();
1950 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
1951 return anObj._retn();
1954 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
1956 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
1957 SMESH::LogicalOR_var anObj = aServant->_this();
1958 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
1959 return anObj._retn();
1962 LinearOrQuadratic_ptr FilterManager_i::CreateLinearOrQuadratic()
1964 SMESH::LinearOrQuadratic_i* aServant = new SMESH::LinearOrQuadratic_i();
1965 SMESH::LinearOrQuadratic_var anObj = aServant->_this();
1966 TPythonDump()<<aServant<<" = "<<this<<".CreateLinearOrQuadratic()";
1967 return anObj._retn();
1970 GroupColor_ptr FilterManager_i::CreateGroupColor()
1972 SMESH::GroupColor_i* aServant = new SMESH::GroupColor_i();
1973 SMESH::GroupColor_var anObj = aServant->_this();
1974 TPythonDump()<<aServant<<" = "<<this<<".CreateGroupColor()";
1975 return anObj._retn();
1978 ElemGeomType_ptr FilterManager_i::CreateElemGeomType()
1980 SMESH::ElemGeomType_i* aServant = new SMESH::ElemGeomType_i();
1981 SMESH::ElemGeomType_var anObj = aServant->_this();
1982 TPythonDump()<<aServant<<" = "<<this<<".CreateElemGeomType()";
1983 return anObj._retn();
1986 Filter_ptr FilterManager_i::CreateFilter()
1988 SMESH::Filter_i* aServant = new SMESH::Filter_i();
1989 SMESH::Filter_var anObj = aServant->_this();
1990 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
1991 return anObj._retn();
1994 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
1996 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
1997 SMESH::FilterLibrary_var anObj = aServant->_this();
1998 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary('"<<aFileName<<"')";
1999 return anObj._retn();
2002 FilterLibrary_ptr FilterManager_i::CreateLibrary()
2004 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
2005 SMESH::FilterLibrary_var anObj = aServant->_this();
2006 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
2007 return anObj._retn();
2010 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
2012 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
2013 return remove( aFileName ) ? false : true;
2016 //=============================================================================
2018 * SMESH_Gen_i::CreateFilterManager
2020 * Create filter manager
2022 //=============================================================================
2024 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
2026 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2027 SMESH::FilterManager_var anObj = aFilter->_this();
2028 return anObj._retn();
2036 //=======================================================================
2037 // name : Filter_i::Filter_i
2038 // Purpose : Constructor
2039 //=======================================================================
2040 Filter_i::Filter_i()
2041 : myPredicate( NULL )
2044 //=======================================================================
2045 // name : Filter_i::~Filter_i
2046 // Purpose : Destructor
2047 //=======================================================================
2048 Filter_i::~Filter_i()
2051 myPredicate->Destroy();
2053 if(!CORBA::is_nil(myMesh))
2056 //TPythonDump()<<this<<".Destroy()";
2059 //=======================================================================
2060 // name : Filter_i::SetPredicate
2061 // Purpose : Set predicate
2062 //=======================================================================
2063 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
2066 myPredicate->Destroy();
2068 myPredicate = SMESH::GetPredicate(thePredicate);
2072 myFilter.SetPredicate( myPredicate->GetPredicate() );
2073 myPredicate->Register();
2074 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
2078 //=======================================================================
2079 // name : Filter_i::GetElementType
2080 // Purpose : Get entity type
2081 //=======================================================================
2082 SMESH::ElementType Filter_i::GetElementType()
2084 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
2087 //=======================================================================
2088 // name : Filter_i::SetMesh
2089 // Purpose : Set mesh
2090 //=======================================================================
2093 SetMesh( SMESH_Mesh_ptr theMesh )
2095 if(!CORBA::is_nil(theMesh))
2096 theMesh->Register();
2098 if(!CORBA::is_nil(myMesh))
2102 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
2109 return GetElementsId(myMesh);
2112 //=======================================================================
2113 // name : Filter_i::GetElementsId
2114 // Purpose : Get ids of entities
2115 //=======================================================================
2118 GetElementsId( Predicate_i* thePredicate,
2119 const SMDS_Mesh* theMesh,
2120 Controls::Filter::TIdSequence& theSequence )
2123 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
2128 GetElementsId( Predicate_i* thePredicate,
2129 SMESH_Mesh_ptr theMesh,
2130 Controls::Filter::TIdSequence& theSequence )
2133 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2134 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
2139 GetElementsId( SMESH_Mesh_ptr theMesh )
2141 SMESH::long_array_var anArray = new SMESH::long_array;
2142 if(!CORBA::is_nil(theMesh) && myPredicate){
2143 Controls::Filter::TIdSequence aSequence;
2144 GetElementsId(myPredicate,theMesh,aSequence);
2145 long i = 0, iEnd = aSequence.size();
2146 anArray->length( iEnd );
2147 for ( ; i < iEnd; i++ )
2148 anArray[ i ] = aSequence[i];
2150 return anArray._retn();
2153 //=======================================================================
2154 // name : getCriteria
2155 // Purpose : Retrieve criterions from predicate
2156 //=======================================================================
2157 static inline bool getCriteria( Predicate_i* thePred,
2158 SMESH::Filter::Criteria_out theCriteria )
2160 int aFType = thePred->GetFunctorType();
2164 case FT_FreeBorders:
2167 case FT_LinearOrQuadratic:
2170 CORBA::ULong i = theCriteria->length();
2171 theCriteria->length( i + 1 );
2173 theCriteria[ i ] = createCriterion();
2175 theCriteria[ i ].Type = aFType;
2176 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
2179 case FT_BelongToGeom:
2181 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
2183 CORBA::ULong i = theCriteria->length();
2184 theCriteria->length( i + 1 );
2186 theCriteria[ i ] = createCriterion();
2188 theCriteria[ i ].Type = FT_BelongToGeom;
2189 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2190 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2191 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2192 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2196 case FT_BelongToPlane:
2197 case FT_BelongToCylinder:
2198 case FT_BelongToGenSurface:
2200 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
2202 CORBA::ULong i = theCriteria->length();
2203 theCriteria->length( i + 1 );
2205 theCriteria[ i ] = createCriterion();
2207 theCriteria[ i ].Type = aFType;
2208 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2209 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2210 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2211 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2215 case FT_LyingOnGeom:
2217 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
2219 CORBA::ULong i = theCriteria->length();
2220 theCriteria->length( i + 1 );
2222 theCriteria[ i ] = createCriterion();
2224 theCriteria[ i ].Type = FT_LyingOnGeom;
2225 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2226 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2227 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2228 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2234 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
2236 CORBA::ULong i = theCriteria->length();
2237 theCriteria->length( i + 1 );
2239 theCriteria[ i ] = createCriterion();
2241 theCriteria[ i ].Type = FT_RangeOfIds;
2242 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
2243 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2247 case FT_BadOrientedVolume:
2249 BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
2251 CORBA::ULong i = theCriteria->length();
2252 theCriteria->length( i + 1 );
2254 theCriteria[ i ] = createCriterion();
2256 theCriteria[ i ].Type = FT_BadOrientedVolume;
2257 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2265 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
2267 CORBA::ULong i = theCriteria->length();
2268 theCriteria->length( i + 1 );
2270 theCriteria[ i ] = createCriterion();
2272 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
2273 theCriteria[ i ].Compare = aFType;
2274 theCriteria[ i ].Threshold = aCompar->GetMargin();
2275 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
2277 if ( aFType == FT_EqualTo )
2279 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
2280 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
2287 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2288 getCriteria( aPred, theCriteria );
2289 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2296 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2297 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2298 if ( !getCriteria( aPred1, theCriteria ) )
2300 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2301 return getCriteria( aPred2, theCriteria );
2305 CORBA::ULong i = theCriteria->length();
2306 theCriteria->length( i + 1 );
2308 theCriteria[ i ] = createCriterion();
2310 GroupColor_i* aPred = dynamic_cast<GroupColor_i*>( thePred );
2311 theCriteria[ i ].Type = aFType;
2312 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2313 theCriteria[ i ].ThresholdStr = aPred->GetColorStr();
2317 case FT_ElemGeomType:
2319 CORBA::ULong i = theCriteria->length();
2320 theCriteria->length( i + 1 );
2322 theCriteria[ i ] = createCriterion();
2324 ElemGeomType_i* aPred = dynamic_cast<ElemGeomType_i*>( thePred );
2325 theCriteria[ i ].Type = aFType;
2326 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2327 theCriteria[ i ].Threshold = (double)aPred->GetGeometryType();
2338 //=======================================================================
2339 // name : Filter_i::GetCriteria
2340 // Purpose : Retrieve criterions from predicate
2341 //=======================================================================
2342 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2344 theCriteria = new SMESH::Filter::Criteria;
2345 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2348 //=======================================================================
2349 // name : Filter_i::SetCriteria
2350 // Purpose : Create new predicate and set criterions in it
2351 //=======================================================================
2352 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2354 if ( myPredicate != 0 )
2355 myPredicate->Destroy();
2357 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2358 FilterManager_ptr aFilterMgr = aFilter->_this();
2360 // CREATE two lists ( PREDICATES and LOG OP )
2363 TPythonDump()<<"aCriteria = []";
2364 std::list<SMESH::Predicate_ptr> aPredicates;
2365 std::list<int> aBinaries;
2366 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2368 int aCriterion = theCriteria[ i ].Type;
2369 int aCompare = theCriteria[ i ].Compare;
2370 double aThreshold = theCriteria[ i ].Threshold;
2371 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2372 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2373 int aUnary = theCriteria[ i ].UnaryOp;
2374 int aBinary = theCriteria[ i ].BinaryOp;
2375 double aTolerance = theCriteria[ i ].Tolerance;
2376 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
2377 long aPrecision = theCriteria[ i ].Precision;
2381 pd << "aCriterion = SMESH.Filter.Criterion(" << aCriterion << "," << aCompare
2382 << "," << aThreshold << ",'" << aThresholdStr;
2383 if (aThresholdID && strlen(aThresholdID))
2384 //pd << "',salome.ObjectToID(" << aThresholdID
2385 pd << "','" << aThresholdID
2386 << "'," << aUnary << "," << aBinary << "," << aTolerance
2387 << "," << aTypeOfElem << "," << aPrecision << ")";
2389 pd << "',''," << aUnary << "," << aBinary << "," << aTolerance
2390 << "," << aTypeOfElem << "," << aPrecision << ")";
2393 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2394 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2396 switch ( aCriterion )
2400 case SMESH::FT_MultiConnection:
2401 aFunctor = aFilterMgr->CreateMultiConnection();
2403 case SMESH::FT_MultiConnection2D:
2404 aFunctor = aFilterMgr->CreateMultiConnection2D();
2406 case SMESH::FT_Length:
2407 aFunctor = aFilterMgr->CreateLength();
2409 case SMESH::FT_Length2D:
2410 aFunctor = aFilterMgr->CreateLength2D();
2412 case SMESH::FT_AspectRatio:
2413 aFunctor = aFilterMgr->CreateAspectRatio();
2415 case SMESH::FT_AspectRatio3D:
2416 aFunctor = aFilterMgr->CreateAspectRatio3D();
2418 case SMESH::FT_Warping:
2419 aFunctor = aFilterMgr->CreateWarping();
2421 case SMESH::FT_MinimumAngle:
2422 aFunctor = aFilterMgr->CreateMinimumAngle();
2424 case SMESH::FT_Taper:
2425 aFunctor = aFilterMgr->CreateTaper();
2427 case SMESH::FT_Skew:
2428 aFunctor = aFilterMgr->CreateSkew();
2430 case SMESH::FT_Area:
2431 aFunctor = aFilterMgr->CreateArea();
2433 case SMESH::FT_Volume3D:
2434 aFunctor = aFilterMgr->CreateVolume3D();
2439 case SMESH::FT_FreeBorders:
2440 aPredicate = aFilterMgr->CreateFreeBorders();
2442 case SMESH::FT_FreeEdges:
2443 aPredicate = aFilterMgr->CreateFreeEdges();
2445 case SMESH::FT_FreeFaces:
2446 aPredicate = aFilterMgr->CreateFreeFaces();
2448 case SMESH::FT_FreeNodes:
2449 aPredicate = aFilterMgr->CreateFreeNodes();
2451 case SMESH::FT_BelongToGeom:
2453 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2454 tmpPred->SetElementType( aTypeOfElem );
2455 tmpPred->SetShape( aThresholdID, aThresholdStr );
2456 tmpPred->SetTolerance( aTolerance );
2457 aPredicate = tmpPred;
2460 case SMESH::FT_BelongToPlane:
2461 case SMESH::FT_BelongToCylinder:
2462 case SMESH::FT_BelongToGenSurface:
2464 SMESH::BelongToSurface_ptr tmpPred;
2465 switch ( aCriterion ) {
2466 case SMESH::FT_BelongToPlane:
2467 tmpPred = aFilterMgr->CreateBelongToPlane(); break;
2468 case SMESH::FT_BelongToCylinder:
2469 tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
2471 tmpPred = aFilterMgr->CreateBelongToGenSurface();
2473 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2474 tmpPred->SetTolerance( aTolerance );
2475 aPredicate = tmpPred;
2478 case SMESH::FT_LyingOnGeom:
2480 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2481 tmpPred->SetElementType( aTypeOfElem );
2482 tmpPred->SetShape( aThresholdID, aThresholdStr );
2483 tmpPred->SetTolerance( aTolerance );
2484 aPredicate = tmpPred;
2487 case SMESH::FT_RangeOfIds:
2489 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2490 tmpPred->SetRangeStr( aThresholdStr );
2491 tmpPred->SetElementType( aTypeOfElem );
2492 aPredicate = tmpPred;
2495 case SMESH::FT_BadOrientedVolume:
2497 aPredicate = aFilterMgr->CreateBadOrientedVolume();
2500 case SMESH::FT_LinearOrQuadratic:
2502 SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
2503 tmpPred->SetElementType( aTypeOfElem );
2504 aPredicate = tmpPred;
2507 case SMESH::FT_GroupColor:
2509 SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor();
2510 tmpPred->SetElementType( aTypeOfElem );
2511 tmpPred->SetColorStr( aThresholdStr );
2512 aPredicate = tmpPred;
2515 case SMESH::FT_ElemGeomType:
2517 SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType();
2518 tmpPred->SetElementType( aTypeOfElem );
2519 tmpPred->SetGeometryType( (GeometryType)(aThreshold + 0.5) );
2520 aPredicate = tmpPred;
2529 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
2531 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
2533 if ( aCompare == SMESH::FT_LessThan )
2534 aComparator = aFilterMgr->CreateLessThan();
2535 else if ( aCompare == SMESH::FT_MoreThan )
2536 aComparator = aFilterMgr->CreateMoreThan();
2537 else if ( aCompare == SMESH::FT_EqualTo )
2538 aComparator = aFilterMgr->CreateEqualTo();
2542 aComparator->SetNumFunctor( aFunctor );
2543 aComparator->SetMargin( aThreshold );
2545 if ( aCompare == FT_EqualTo )
2547 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
2548 anEqualTo->SetTolerance( aTolerance );
2551 aPredicate = aComparator;
2553 aFunctor->SetPrecision( aPrecision );
2557 if ( aUnary == FT_LogicalNOT )
2559 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
2560 aNotPred->SetPredicate( aPredicate );
2561 aPredicate = aNotPred;
2565 aPredicates.push_back( aPredicate );
2566 aBinaries.push_back( aBinary );
2567 TPythonDump()<<"aCriteria.append(aCriterion)";
2570 TPythonDump()<<this<<".SetCriteria(aCriteria)";
2572 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
2574 // combine all "AND" operations
2576 std::list<SMESH::Predicate_ptr> aResList;
2578 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
2579 std::list<int>::iterator aBinaryIter;
2581 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
2582 int aPrevBinary = SMESH::FT_Undefined;
2584 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
2585 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
2586 ++aPredIter, ++aBinaryIter )
2588 int aCurrBinary = *aBinaryIter;
2590 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
2592 if ( aPrevBinary == SMESH::FT_LogicalAND )
2595 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2596 aBinaryPred->SetPredicate1( aPrevPredicate );
2597 aBinaryPred->SetPredicate2( *aPredIter );
2598 aCurrPred = aBinaryPred;
2601 aCurrPred = *aPredIter;
2603 if ( aCurrBinary != SMESH::FT_LogicalAND )
2604 aResList.push_back( aCurrPred );
2606 aPrevPredicate = aCurrPred;
2607 aPrevBinary = aCurrBinary;
2610 // combine all "OR" operations
2612 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2614 if ( aResList.size() == 1 )
2615 aResPredicate = *aResList.begin();
2616 else if ( aResList.size() > 1 )
2618 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2619 aResPredicate = *anIter;
2621 for ( ; anIter != aResList.end(); ++anIter )
2623 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2624 aBinaryPred->SetPredicate1( aResPredicate );
2625 aBinaryPred->SetPredicate2( *anIter );
2626 aResPredicate = aBinaryPred;
2630 SetPredicate( aResPredicate );
2632 return !aResPredicate->_is_nil();
2635 //=======================================================================
2636 // name : Filter_i::GetPredicate_i
2637 // Purpose : Get implementation of predicate
2638 //=======================================================================
2639 Predicate_i* Filter_i::GetPredicate_i()
2644 //=======================================================================
2645 // name : Filter_i::GetPredicate
2646 // Purpose : Get predicate
2647 //=======================================================================
2648 Predicate_ptr Filter_i::GetPredicate()
2650 if ( myPredicate == 0 )
2651 return SMESH::Predicate::_nil();
2654 SMESH::Predicate_var anObj = myPredicate->_this();
2655 return anObj._retn();
2663 #define ATTR_TYPE "type"
2664 #define ATTR_COMPARE "compare"
2665 #define ATTR_THRESHOLD "threshold"
2666 #define ATTR_UNARY "unary"
2667 #define ATTR_BINARY "binary"
2668 #define ATTR_THRESHOLD_STR "threshold_str"
2669 #define ATTR_TOLERANCE "tolerance"
2670 #define ATTR_ELEMENT_TYPE "ElementType"
2672 //=======================================================================
2674 // Purpose : Convert bool to LDOMString
2675 //=======================================================================
2676 static inline LDOMString toString( CORBA::Boolean val )
2678 return val ? "logical not" : "";
2681 //=======================================================================
2683 // Purpose : Convert LDOMString to bool
2684 //=======================================================================
2685 static inline bool toBool( const LDOMString& theStr )
2687 return theStr.equals( "logical not" );
2690 //=======================================================================
2692 // Purpose : Convert double to LDOMString
2693 //=======================================================================
2694 static inline LDOMString toString( CORBA::Double val )
2697 sprintf( a, "%e", val );
2698 return LDOMString( a );
2701 //=======================================================================
2703 // Purpose : Convert LDOMString to double
2704 //=======================================================================
2705 static inline double toDouble( const LDOMString& theStr )
2707 return atof( theStr.GetString() );
2710 //=======================================================================
2712 // Purpose : Convert functor type to LDOMString
2713 //=======================================================================
2714 static inline LDOMString toString( CORBA::Long theType )
2718 case FT_AspectRatio : return "Aspect ratio";
2719 case FT_Warping : return "Warping";
2720 case FT_MinimumAngle : return "Minimum angle";
2721 case FT_Taper : return "Taper";
2722 case FT_Skew : return "Skew";
2723 case FT_Area : return "Area";
2724 case FT_Volume3D : return "Volume3D";
2725 case FT_BelongToGeom : return "Belong to Geom";
2726 case FT_BelongToPlane : return "Belong to Plane";
2727 case FT_BelongToCylinder: return "Belong to Cylinder";
2728 case FT_BelongToGenSurface: return "Belong to Generic Surface";
2729 case FT_LyingOnGeom : return "Lying on Geom";
2730 case FT_BadOrientedVolume: return "Bad Oriented Volume";
2731 case FT_RangeOfIds : return "Range of IDs";
2732 case FT_FreeBorders : return "Free borders";
2733 case FT_FreeEdges : return "Free edges";
2734 case FT_FreeFaces : return "Free faces";
2735 case FT_FreeNodes : return "Free nodes";
2736 case FT_MultiConnection : return "Borders at multi-connections";
2737 case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2738 case FT_Length : return "Length";
2739 case FT_Length2D : return "Length 2D";
2740 case FT_LessThan : return "Less than";
2741 case FT_MoreThan : return "More than";
2742 case FT_EqualTo : return "Equal to";
2743 case FT_LogicalNOT : return "Not";
2744 case FT_LogicalAND : return "And";
2745 case FT_LogicalOR : return "Or";
2746 case FT_GroupColor : return "Color of Group";
2747 case FT_LinearOrQuadratic : return "Linear or Quadratic";
2748 case FT_ElemGeomType : return "Element geomtry type";
2749 case FT_Undefined : return "";
2750 default : return "";
2754 //=======================================================================
2755 // name : toFunctorType
2756 // Purpose : Convert LDOMString to functor type
2757 //=======================================================================
2758 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
2760 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
2761 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
2762 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
2763 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
2764 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
2765 else if ( theStr.equals( "Area" ) ) return FT_Area;
2766 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
2767 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
2768 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
2769 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
2770 else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface;
2771 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
2772 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
2773 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
2774 else if ( theStr.equals( "Free faces" ) ) return FT_FreeFaces;
2775 else if ( theStr.equals( "Free nodes" ) ) return FT_FreeNodes;
2776 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
2777 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
2778 else if ( theStr.equals( "Length" ) ) return FT_Length;
2779 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
2780 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
2781 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
2782 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
2783 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
2784 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
2785 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
2786 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
2787 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
2788 else if ( theStr.equals( "Color of Group" ) ) return FT_GroupColor;
2789 else if ( theStr.equals( "Linear or Quadratic" ) ) return FT_LinearOrQuadratic;
2790 else if ( theStr.equals( "Element geomtry type" ) ) return FT_ElemGeomType;
2791 else if ( theStr.equals( "" ) ) return FT_Undefined;
2792 else return FT_Undefined;
2795 //=======================================================================
2796 // name : toFunctorType
2797 // Purpose : Convert LDOMString to value of ElementType enumeration
2798 //=======================================================================
2799 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
2801 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
2802 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
2803 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
2804 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
2805 else return SMESH::ALL;
2808 //=======================================================================
2810 // Purpose : Convert ElementType to string
2811 //=======================================================================
2812 static inline LDOMString toString( const SMESH::ElementType theType )
2816 case SMESH::NODE : return "NODE";
2817 case SMESH::EDGE : return "EDGE";
2818 case SMESH::FACE : return "FACE";
2819 case SMESH::VOLUME : return "VOLUME";
2820 case SMESH::ALL : return "ALL";
2821 default : return "";
2825 //=======================================================================
2826 // name : findFilter
2827 // Purpose : Find filter in document
2828 //=======================================================================
2829 static LDOM_Element findFilter( const char* theFilterName,
2830 const LDOM_Document& theDoc,
2831 LDOM_Node* theParent = 0 )
2833 LDOM_Element aRootElement = theDoc.getDocumentElement();
2834 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
2835 return LDOM_Element();
2837 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
2838 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
2840 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
2841 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2843 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
2844 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
2845 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
2847 if ( theParent != 0 )
2848 *theParent = aTypeNode;
2849 return (LDOM_Element&)aFilter;
2853 return LDOM_Element();
2856 //=======================================================================
2857 // name : getSectionName
2858 // Purpose : Get name of section of filters
2859 //=======================================================================
2860 static const char* getSectionName( const ElementType theType )
2864 case SMESH::NODE : return "Filters for nodes";
2865 case SMESH::EDGE : return "Filters for edges";
2866 case SMESH::FACE : return "Filters for faces";
2867 case SMESH::VOLUME : return "Filters for volumes";
2868 case SMESH::ALL : return "Filters for elements";
2869 default : return "";
2873 //=======================================================================
2874 // name : getSection
2875 // Purpose : Create section for filters corresponding to the entity type
2876 //=======================================================================
2877 static LDOM_Node getSection( const ElementType theType,
2878 LDOM_Document& theDoc,
2879 const bool toCreate = false )
2881 LDOM_Element aRootElement = theDoc.getDocumentElement();
2882 if ( aRootElement.isNull() )
2886 bool anExist = false;
2887 const char* aSectionName = getSectionName( theType );
2888 if ( strcmp( aSectionName, "" ) == 0 )
2891 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
2893 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
2895 aNode = aSections.item( i );
2896 LDOM_Element& anItem = ( LDOM_Element& )aNode;
2897 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
2904 // Create new section if necessary
2909 LDOM_Element aNewItem = theDoc.createElement( "section" );
2910 aNewItem.setAttribute( "name", aSectionName );
2911 aRootElement.appendChild( aNewItem );
2921 //=======================================================================
2922 // name : createFilterItem
2923 // Purpose : Create filter item or LDOM document
2924 //=======================================================================
2925 static LDOM_Element createFilterItem( const char* theName,
2926 SMESH::Filter_ptr theFilter,
2927 LDOM_Document& theDoc )
2929 // create new filter in document
2930 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
2931 aFilterItem.setAttribute( "name", theName );
2933 // save filter criterions
2934 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2936 if ( !theFilter->GetCriteria( aCriteria ) )
2937 return LDOM_Element();
2939 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
2941 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
2943 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
2944 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
2945 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
2946 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
2947 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
2949 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
2950 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
2951 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
2952 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
2954 aFilterItem.appendChild( aCriterionItem );
2960 //=======================================================================
2961 // name : FilterLibrary_i::FilterLibrary_i
2962 // Purpose : Constructor
2963 //=======================================================================
2964 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
2966 myFileName = strdup( theFileName );
2967 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
2968 myFilterMgr = aFilterMgr->_this();
2972 // Try to use existing library file
2973 bool anExists = false;
2974 if ( !aParser.parse( myFileName ) )
2976 myDoc = aParser.getDocument();
2979 // Create a new XML document if it doesn't exist
2981 myDoc = LDOM_Document::createDocument( LDOMString() );
2983 LDOM_Element aRootElement = myDoc.getDocumentElement();
2984 if ( aRootElement.isNull() )
2986 // If the existing document is empty --> try to create a new one
2988 myDoc = LDOM_Document::createDocument( LDOMString() );
2992 //=======================================================================
2993 // name : FilterLibrary_i::FilterLibrary_i
2994 // Purpose : Constructor
2995 //=======================================================================
2996 FilterLibrary_i::FilterLibrary_i()
2999 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
3000 myFilterMgr = aFilter->_this();
3002 myDoc = LDOM_Document::createDocument( LDOMString() );
3005 FilterLibrary_i::~FilterLibrary_i()
3008 //TPythonDump()<<this<<".Destroy()";
3011 //=======================================================================
3012 // name : FilterLibrary_i::Copy
3013 // Purpose : Create filter and initialize it with values from library
3014 //=======================================================================
3015 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
3017 Filter_ptr aRes = Filter::_nil();
3018 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
3020 if ( aFilter.isNull() )
3023 std::list<SMESH::Filter::Criterion> aCriteria;
3025 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
3026 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
3028 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
3030 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
3031 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
3032 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
3033 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
3034 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
3036 SMESH::Filter::Criterion aCriterion = createCriterion();
3038 aCriterion.Type = toFunctorType( aTypeStr );
3039 aCriterion.Compare = toFunctorType( aCompareStr );
3040 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
3041 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
3043 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
3045 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
3047 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3048 ? val : atof( str.GetString() );
3050 str = aCrit->getAttribute( ATTR_TOLERANCE );
3051 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3052 ? val : atof( str.GetString() );
3054 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
3055 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
3058 sprintf( a, "%d", val );
3059 aCriterion.ThresholdStr = strdup( a );
3062 aCriterion.ThresholdStr = str.GetString();
3064 aCriteria.push_back( aCriterion );
3067 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
3068 aCriteriaVar->length( aCriteria.size() );
3071 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
3073 for( ; anIter != aCriteria.end(); ++anIter )
3074 aCriteriaVar[ i++ ] = *anIter;
3076 aRes = myFilterMgr->CreateFilter();
3077 aRes->SetCriteria( aCriteriaVar.inout() );
3079 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
3084 //=======================================================================
3085 // name : FilterLibrary_i::SetFileName
3086 // Purpose : Set file name for library
3087 //=======================================================================
3088 void FilterLibrary_i::SetFileName( const char* theFileName )
3091 myFileName = strdup( theFileName );
3092 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
3095 //=======================================================================
3096 // name : FilterLibrary_i::GetFileName
3097 // Purpose : Get file name of library
3098 //=======================================================================
3099 char* FilterLibrary_i::GetFileName()
3101 return CORBA::string_dup( myFileName );
3104 //=======================================================================
3105 // name : FilterLibrary_i::Add
3106 // Purpose : Add new filter to library
3107 //=======================================================================
3108 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
3110 // if filter already in library or entry filter is null do nothing
3111 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3112 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
3115 // get section corresponding to the filter type
3116 ElementType anEntType = theFilter->GetElementType();
3118 LDOM_Node aSection = getSection( anEntType, myDoc, true );
3119 if ( aSection.isNull() )
3122 // create filter item
3123 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
3124 if ( aFilterItem.isNull() )
3128 aSection.appendChild( aFilterItem );
3129 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3130 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
3135 //=======================================================================
3136 // name : FilterLibrary_i::Add
3137 // Purpose : Add new filter to library
3138 //=======================================================================
3139 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
3141 // if filter already in library or entry filter is null do nothing
3142 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3143 if ( !aFilterNode.isNull() )
3146 LDOM_Node aSection = getSection( theType, myDoc, true );
3147 if ( aSection.isNull() )
3150 // create filter item
3151 Filter_var aFilter = myFilterMgr->CreateFilter();
3153 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
3154 if ( aFilterItem.isNull() )
3158 aSection.appendChild( aFilterItem );
3159 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
3164 //=======================================================================
3165 // name : FilterLibrary_i::Delete
3166 // Purpose : Delete filter from library
3167 //=======================================================================
3168 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
3170 LDOM_Node aParentNode;
3171 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
3172 if ( aFilterNode.isNull() || aParentNode.isNull() )
3175 aParentNode.removeChild( aFilterNode );
3176 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
3180 //=======================================================================
3181 // name : FilterLibrary_i::Replace
3182 // Purpose : Replace existing filter with entry filter.
3183 // IMPORTANT : If filter does not exist it is not created
3184 //=======================================================================
3185 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
3186 const char* theNewName,
3187 Filter_ptr theFilter )
3189 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
3190 if ( aFilterItem.isNull() || theFilter->_is_nil() )
3193 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
3194 if ( aNewItem.isNull() )
3198 aFilterItem.ReplaceElement( aNewItem );
3199 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3200 TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
3205 //=======================================================================
3206 // name : FilterLibrary_i::Save
3207 // Purpose : Save library on disk
3208 //=======================================================================
3209 CORBA::Boolean FilterLibrary_i::Save()
3211 if ( myFileName == 0 || strlen( myFileName ) == 0 )
3214 FILE* aOutFile = fopen( myFileName, "wt" );
3218 LDOM_XmlWriter aWriter( aOutFile );
3219 aWriter.SetIndentation( 2 );
3223 TPythonDump()<<this<<".Save()";
3227 //=======================================================================
3228 // name : FilterLibrary_i::SaveAs
3229 // Purpose : Save library on disk
3230 //=======================================================================
3231 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
3233 myFileName = strdup ( aFileName );
3234 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
3238 //=======================================================================
3239 // name : FilterLibrary_i::IsPresent
3240 // Purpose : Verify whether filter is in library
3241 //=======================================================================
3242 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
3244 return !findFilter( theFilterName, myDoc ).isNull();
3247 //=======================================================================
3248 // name : FilterLibrary_i::NbFilters
3249 // Purpose : Return amount of filters in library
3250 //=======================================================================
3251 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
3253 string_array_var aNames = GetNames( theType );
3254 return aNames->length();
3257 //=======================================================================
3258 // name : FilterLibrary_i::GetNames
3259 // Purpose : Get names of filters from library
3260 //=======================================================================
3261 string_array* FilterLibrary_i::GetNames( ElementType theType )
3263 string_array_var anArray = new string_array;
3264 TColStd_SequenceOfHAsciiString aSeq;
3266 LDOM_Node aSection = getSection( theType, myDoc, false );
3268 if ( !aSection.isNull() )
3270 for ( LDOM_Node aFilter = aSection.getFirstChild();
3271 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3273 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
3274 aSeq.Append( new TCollection_HAsciiString(
3275 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
3279 anArray->length( aSeq.Length() );
3280 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
3281 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
3283 return anArray._retn();
3286 //=======================================================================
3287 // name : FilterLibrary_i::GetAllNames
3288 // Purpose : Get names of filters from library
3289 //=======================================================================
3290 string_array* FilterLibrary_i::GetAllNames()
3292 string_array_var aResArray = new string_array;
3293 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
3295 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
3297 int aPrevLength = aResArray->length();
3298 aResArray->length( aPrevLength + aNames->length() );
3299 for ( int i = 0, n = aNames->length(); i < n; i++ )
3300 aResArray[ aPrevLength + i ] = aNames[ i ];
3303 return aResArray._retn();