1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 // File : SMESH_Filter_i.cxx
25 // Author : Alexey Petrov, OCC
28 #include "SMESH_Filter_i.hxx"
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_PythonDump.hxx"
33 #include "SMDS_Mesh.hxx"
34 #include "SMDS_MeshNode.hxx"
35 #include "SMDS_MeshElement.hxx"
36 #include "SMDS_ElemIterator.hxx"
38 #include "SMESHDS_Mesh.hxx"
40 #include <BRep_Tool.hxx>
41 #include <Geom_CylindricalSurface.hxx>
42 #include <Geom_Plane.hxx>
43 #include <LDOMParser.hxx>
44 #include <LDOMString.hxx>
45 #include <LDOM_Document.hxx>
46 #include <LDOM_Element.hxx>
47 #include <LDOM_Node.hxx>
48 #include <LDOM_XmlWriter.hxx>
49 #include <Precision.hxx>
50 #include <TColStd_ListIteratorOfListOfInteger.hxx>
51 #include <TColStd_ListIteratorOfListOfReal.hxx>
52 #include <TColStd_ListOfInteger.hxx>
53 #include <TColStd_ListOfReal.hxx>
54 #include <TColStd_SequenceOfHAsciiString.hxx>
55 #include <TCollection_HAsciiString.hxx>
57 #include <TopExp_Explorer.hxx>
59 #include <TopoDS_Face.hxx>
60 #include <TopoDS_Shape.hxx>
61 #include <TopTools_IndexedMapOfShape.hxx>
63 using namespace SMESH;
64 using namespace SMESH::Controls;
70 GetPredicate( Predicate_ptr thePredicate )
72 return DownCast<Predicate_i*>(thePredicate);
79 Description : Predicate for verifying whether entity belongs to
80 specified geometrical support
83 Controls::BelongToGeom::BelongToGeom()
87 myTolerance(Precision::Confusion())
90 void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
92 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
96 void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
102 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
103 const TopoDS_Shape& theShape)
105 if (theMap.Contains(theShape)) return true;
107 if (theShape.ShapeType() == TopAbs_COMPOUND ||
108 theShape.ShapeType() == TopAbs_COMPSOLID)
110 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
111 for (; anIt.More(); anIt.Next())
113 if (!IsSubShape(theMap, anIt.Value())) {
123 void Controls::BelongToGeom::init()
125 if (!myMeshDS || myShape.IsNull()) return;
127 // is subshape of main shape?
128 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
129 if (aMainShape.IsNull()) {
130 myIsSubshape = false;
133 TopTools_IndexedMapOfShape aMap;
134 TopExp::MapShapes(aMainShape, aMap);
135 myIsSubshape = IsSubShape(aMap, myShape);
140 myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
141 myElementsOnShapePtr->SetTolerance(myTolerance);
142 myElementsOnShapePtr->SetAllNodes(true); // belong, while false means "lays on"
143 myElementsOnShapePtr->SetMesh(myMeshDS);
144 myElementsOnShapePtr->SetShape(myShape, myType);
148 static bool IsContains( const SMESHDS_Mesh* theMeshDS,
149 const TopoDS_Shape& theShape,
150 const SMDS_MeshElement* theElem,
151 TopAbs_ShapeEnum theFindShapeEnum,
152 TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE )
154 TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
156 while( anExp.More() )
158 const TopoDS_Shape& aShape = anExp.Current();
159 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
160 if( aSubMesh->Contains( theElem ) )
168 bool Controls::BelongToGeom::IsSatisfy (long theId)
170 if (myMeshDS == 0 || myShape.IsNull())
175 return myElementsOnShapePtr->IsSatisfy(theId);
179 if (myType == SMDSAbs_Node)
181 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
183 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
184 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
185 switch( aTypeOfPosition )
187 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
188 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
189 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
190 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
196 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
198 if( myType == SMDSAbs_All )
200 return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
201 IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
202 IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
203 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
205 else if( myType == anElem->GetType() )
209 case SMDSAbs_Edge : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
210 case SMDSAbs_Face : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
211 case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
212 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
221 void Controls::BelongToGeom::SetType (SMDSAbs_ElementType theType)
227 SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
232 TopoDS_Shape Controls::BelongToGeom::GetShape()
237 const SMESHDS_Mesh* Controls::BelongToGeom::GetMeshDS() const
242 void Controls::BelongToGeom::SetTolerance (double theTolerance)
244 myTolerance = theTolerance;
249 double Controls::BelongToGeom::GetTolerance()
256 Description : Predicate for verifying whether entiy lying or partially lying on
257 specified geometrical support
260 Controls::LyingOnGeom::LyingOnGeom()
264 myTolerance(Precision::Confusion())
267 void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
269 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
273 void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
279 void Controls::LyingOnGeom::init()
281 if (!myMeshDS || myShape.IsNull()) return;
283 // is subshape of main shape?
284 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
285 if (aMainShape.IsNull()) {
286 myIsSubshape = false;
289 TopTools_IndexedMapOfShape aMap;
290 TopExp::MapShapes(aMainShape, aMap);
291 myIsSubshape = IsSubShape(aMap, myShape);
296 myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
297 myElementsOnShapePtr->SetTolerance(myTolerance);
298 myElementsOnShapePtr->SetAllNodes(false); // lays on, while true means "belong"
299 myElementsOnShapePtr->SetMesh(myMeshDS);
300 myElementsOnShapePtr->SetShape(myShape, myType);
304 bool Controls::LyingOnGeom::IsSatisfy( long theId )
306 if ( myMeshDS == 0 || myShape.IsNull() )
311 return myElementsOnShapePtr->IsSatisfy(theId);
315 if( myType == SMDSAbs_Node )
317 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
319 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
320 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
321 switch( aTypeOfPosition )
323 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
324 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
325 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
326 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
332 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
334 if( myType == SMDSAbs_All )
336 return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
337 Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
338 Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
339 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
341 else if( myType == anElem->GetType() )
345 case SMDSAbs_Edge : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
346 case SMDSAbs_Face : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
347 case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
348 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
357 void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
363 SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
368 TopoDS_Shape Controls::LyingOnGeom::GetShape()
373 const SMESHDS_Mesh* Controls::LyingOnGeom::GetMeshDS() const
378 void Controls::LyingOnGeom::SetTolerance (double theTolerance)
380 myTolerance = theTolerance;
385 double Controls::LyingOnGeom::GetTolerance()
390 bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh* theMeshDS,
391 const TopoDS_Shape& theShape,
392 const SMDS_MeshElement* theElem,
393 TopAbs_ShapeEnum theFindShapeEnum,
394 TopAbs_ShapeEnum theAvoidShapeEnum )
396 if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
399 TopTools_IndexedMapOfShape aSubShapes;
400 TopExp::MapShapes( theShape, aSubShapes );
402 for (int i = 1; i <= aSubShapes.Extent(); i++)
404 const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
406 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
407 if( aSubMesh->Contains( theElem ) )
410 SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
411 while ( aNodeIt->more() )
413 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
414 SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
415 while ( anElemIt->more() )
417 const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
418 if (anElement == theElem)
434 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
436 SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
437 return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
442 toArray( const TColStd_ListOfInteger& aList )
444 SMESH::long_array_var anArray = new SMESH::long_array;
445 anArray->length( aList.Extent() );
446 TColStd_ListIteratorOfListOfInteger anIter( aList );
448 for( ; anIter.More(); anIter.Next() )
449 anArray[ i++ ] = anIter.Value();
451 return anArray._retn();
456 toArray( const TColStd_ListOfReal& aList )
458 SMESH::double_array_var anArray = new SMESH::double_array;
459 anArray->length( aList.Extent() );
460 TColStd_ListIteratorOfListOfReal anIter( aList );
462 for( ; anIter.More(); anIter.Next() )
463 anArray[ i++ ] = anIter.Value();
465 return anArray._retn();
468 static SMESH::Filter::Criterion createCriterion()
470 SMESH::Filter::Criterion aCriterion;
472 aCriterion.Type = FT_Undefined;
473 aCriterion.Compare = FT_Undefined;
474 aCriterion.Threshold = 0;
475 aCriterion.UnaryOp = FT_Undefined;
476 aCriterion.BinaryOp = FT_Undefined;
477 aCriterion.ThresholdStr = "";
478 aCriterion.ThresholdID = "";
479 aCriterion.Tolerance = Precision::Confusion();
480 aCriterion.TypeOfElement = SMESH::ALL;
481 aCriterion.Precision = -1;
486 static TopoDS_Shape getShapeByName( const char* theName )
490 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
491 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
492 if (!CORBA::is_nil(aStudy))
494 SALOMEDS::Study::ListOfSObject_var aList =
495 aStudy->FindObjectByName( theName, "GEOM" );
496 if ( aList->length() > 0 )
498 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
499 if ( !aGeomObj->_is_nil() )
501 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
502 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
508 return TopoDS_Shape();
511 static TopoDS_Shape getShapeByID (const char* theID)
513 if (theID != 0 && theID != "") {
514 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
515 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
517 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
518 SALOMEDS::GenericAttribute_var anAttr;
519 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
520 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
521 CORBA::String_var aVal = anIOR->Value();
522 CORBA::Object_var obj = aStudy->ConvertIORToObject(aVal);
523 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
525 if (!aGeomObj->_is_nil()) {
526 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
527 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
533 return TopoDS_Shape();
536 static char* getShapeNameByID (const char* theID)
538 char* aName = (char*)"";
540 if (theID != 0 && theID != "") {
541 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
542 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
544 //SALOMEDS::SObject_var aSObj = aStudy->FindObjectIOR( theID );
545 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
546 SALOMEDS::GenericAttribute_var anAttr;
547 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeName")) {
548 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
549 aName = aNameAttr->Value();
563 Description : An abstact class for all functors
565 Functor_i::Functor_i():
566 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
568 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
569 //PortableServer::ObjectId_var anObjectId =
570 // SMESH_Gen_i::GetPOA()->activate_object( this );
573 Functor_i::~Functor_i()
575 //TPythonDump()<<this<<".Destroy()";
578 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
580 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
581 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
584 ElementType Functor_i::GetElementType()
586 return ( ElementType )myFunctorPtr->GetType();
591 Class : NumericalFunctor_i
592 Description : Base class for numerical functors
594 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
596 return myNumericalFunctorPtr->GetValue( theId );
599 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
601 myNumericalFunctorPtr->SetPrecision( thePrecision );
602 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
605 CORBA::Long NumericalFunctor_i::GetPrecision()
607 return myNumericalFunctorPtr->GetPrecision();
610 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
612 return myNumericalFunctorPtr;
617 Class : SMESH_MinimumAngle
618 Description : Functor for calculation of minimum angle
620 MinimumAngle_i::MinimumAngle_i()
622 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
623 myFunctorPtr = myNumericalFunctorPtr;
626 FunctorType MinimumAngle_i::GetFunctorType()
628 return SMESH::FT_MinimumAngle;
634 Description : Functor for calculating aspect ratio
636 AspectRatio_i::AspectRatio_i()
638 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
639 myFunctorPtr = myNumericalFunctorPtr;
642 FunctorType AspectRatio_i::GetFunctorType()
644 return SMESH::FT_AspectRatio;
649 Class : AspectRatio3D
650 Description : Functor for calculating aspect ratio 3D
652 AspectRatio3D_i::AspectRatio3D_i()
654 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
655 myFunctorPtr = myNumericalFunctorPtr;
658 FunctorType AspectRatio3D_i::GetFunctorType()
660 return SMESH::FT_AspectRatio3D;
666 Description : Functor for calculating warping
668 Warping_i::Warping_i()
670 myNumericalFunctorPtr.reset( new Controls::Warping() );
671 myFunctorPtr = myNumericalFunctorPtr;
674 FunctorType Warping_i::GetFunctorType()
676 return SMESH::FT_Warping;
682 Description : Functor for calculating taper
686 myNumericalFunctorPtr.reset( new Controls::Taper() );
687 myFunctorPtr = myNumericalFunctorPtr;
690 FunctorType Taper_i::GetFunctorType()
692 return SMESH::FT_Taper;
698 Description : Functor for calculating skew in degrees
702 myNumericalFunctorPtr.reset( new Controls::Skew() );
703 myFunctorPtr = myNumericalFunctorPtr;
706 FunctorType Skew_i::GetFunctorType()
708 return SMESH::FT_Skew;
713 Description : Functor for calculating area
717 myNumericalFunctorPtr.reset( new Controls::Area() );
718 myFunctorPtr = myNumericalFunctorPtr;
721 FunctorType Area_i::GetFunctorType()
723 return SMESH::FT_Area;
728 Description : Functor for calculating volume of 3D element
730 Volume3D_i::Volume3D_i()
732 myNumericalFunctorPtr.reset( new Controls::Volume() );
733 myFunctorPtr = myNumericalFunctorPtr;
736 FunctorType Volume3D_i::GetFunctorType()
738 return SMESH::FT_Volume3D;
743 Description : Functor for calculating length off edge
747 myNumericalFunctorPtr.reset( new Controls::Length() );
748 myFunctorPtr = myNumericalFunctorPtr;
751 FunctorType Length_i::GetFunctorType()
753 return SMESH::FT_Length;
758 Description : Functor for calculating length of edge
760 Length2D_i::Length2D_i()
762 myNumericalFunctorPtr.reset( new Controls::Length2D() );
763 myFunctorPtr = myNumericalFunctorPtr;
766 FunctorType Length2D_i::GetFunctorType()
768 return SMESH::FT_Length2D;
771 SMESH::Length2D::Values* Length2D_i::GetValues()
773 INFOS("Length2D_i::GetValues");
774 SMESH::Controls::Length2D::TValues aValues;
775 (dynamic_cast<SMESH::Controls::Length2D*>(myFunctorPtr.get()))->GetValues( aValues );
777 long i = 0, iEnd = aValues.size();
779 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
780 aResult->length(iEnd);
782 SMESH::Controls::Length2D::TValues::const_iterator anIter;
783 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
785 const SMESH::Controls::Length2D::Value& aVal = *anIter;
786 SMESH::Length2D::Value &aValue = aResult[ i ];
788 aValue.myLength = aVal.myLength;
789 aValue.myPnt1 = aVal.myPntId[ 0 ];
790 aValue.myPnt2 = aVal.myPntId[ 1 ];
793 INFOS("Length2D_i::GetValuess~");
794 return aResult._retn();
798 Class : MultiConnection_i
799 Description : Functor for calculating number of faces conneted to the edge
801 MultiConnection_i::MultiConnection_i()
803 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
804 myFunctorPtr = myNumericalFunctorPtr;
807 FunctorType MultiConnection_i::GetFunctorType()
809 return SMESH::FT_MultiConnection;
813 Class : MultiConnection2D_i
814 Description : Functor for calculating number of faces conneted to the edge
816 MultiConnection2D_i::MultiConnection2D_i()
818 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
819 myFunctorPtr = myNumericalFunctorPtr;
822 FunctorType MultiConnection2D_i::GetFunctorType()
824 return SMESH::FT_MultiConnection2D;
827 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
829 INFOS("MultiConnection2D_i::GetValues");
830 SMESH::Controls::MultiConnection2D::MValues aValues;
831 (dynamic_cast<SMESH::Controls::MultiConnection2D*>(myFunctorPtr.get()))->GetValues( aValues );
833 long i = 0, iEnd = aValues.size();
835 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
836 aResult->length(iEnd);
838 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
839 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
841 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
842 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
844 aValue.myPnt1 = aVal.myPntId[ 0 ];
845 aValue.myPnt2 = aVal.myPntId[ 1 ];
846 aValue.myNbConnects = (*anIter).second;
849 INFOS("Multiconnection2D_i::GetValuess~");
850 return aResult._retn();
860 Description : Base class for all predicates
862 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
864 return myPredicatePtr->IsSatisfy( theId );
867 Controls::PredicatePtr Predicate_i::GetPredicate()
869 return myPredicatePtr;
873 Class : BadOrientedVolume_i
874 Description : Verify whether a mesh volume is incorrectly oriented from
875 the point of view of MED convention
877 BadOrientedVolume_i::BadOrientedVolume_i()
879 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
880 myFunctorPtr = myPredicatePtr = control;
883 FunctorType BadOrientedVolume_i::GetFunctorType()
885 return SMESH::FT_BadOrientedVolume;
889 Class : BelongToGeom_i
890 Description : Predicate for selection on geometrical support
892 BelongToGeom_i::BelongToGeom_i()
894 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
895 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
900 BelongToGeom_i::~BelongToGeom_i()
906 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
908 if ( theGeom->_is_nil() )
910 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
911 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
912 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
913 myBelongToGeomPtr->SetGeom( aLocShape );
914 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
917 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
919 myBelongToGeomPtr->SetGeom( theShape );
922 void BelongToGeom_i::SetElementType(ElementType theType){
923 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
924 TPythonDump()<<this<<".SetElementType("<<theType<<")";
927 FunctorType BelongToGeom_i::GetFunctorType()
929 return SMESH::FT_BelongToGeom;
932 void BelongToGeom_i::SetShapeName( const char* theName )
935 myShapeName = strdup( theName );
936 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
937 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
940 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
943 myShapeName = strdup( theName );
946 myShapeID = strdup( theID );
950 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
951 myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
953 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
956 char* BelongToGeom_i::GetShapeName()
958 return CORBA::string_dup( myShapeName );
961 char* BelongToGeom_i::GetShapeID()
963 return CORBA::string_dup( myShapeID );
966 void BelongToGeom_i::SetTolerance( CORBA::Double theToler )
968 myBelongToGeomPtr->SetTolerance( theToler );
969 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
972 CORBA::Double BelongToGeom_i::GetTolerance()
974 return myBelongToGeomPtr->GetTolerance();
978 Class : BelongToSurface_i
979 Description : Predicate for selection on geometrical support
981 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
983 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
984 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
987 mySurfaceType = theSurfaceType;
990 BelongToSurface_i::~BelongToSurface_i()
996 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
998 if ( theGeom->_is_nil() )
1000 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1001 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1002 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1004 if ( aLocShape.ShapeType() == TopAbs_FACE )
1006 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
1007 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
1009 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1014 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
1017 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
1020 myShapeName = strdup( theName );
1021 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1022 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
1025 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
1028 myShapeName = strdup( theName );
1031 myShapeID = strdup( theID );
1035 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1036 myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
1038 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1041 char* BelongToSurface_i::GetShapeName()
1043 return CORBA::string_dup( myShapeName );
1046 char* BelongToSurface_i::GetShapeID()
1048 return CORBA::string_dup( myShapeID );
1051 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
1053 myElementsOnSurfacePtr->SetTolerance( theToler );
1054 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1057 CORBA::Double BelongToSurface_i::GetTolerance()
1059 return myElementsOnSurfacePtr->GetTolerance();
1062 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
1064 myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
1065 TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
1068 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
1070 return myElementsOnSurfacePtr->GetUseBoundaries();
1075 Class : BelongToPlane_i
1076 Description : Verify whether mesh element lie in pointed Geom planar object
1079 BelongToPlane_i::BelongToPlane_i()
1080 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
1084 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1086 BelongToSurface_i::SetSurface( theGeom, theType );
1087 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
1090 FunctorType BelongToPlane_i::GetFunctorType()
1092 return FT_BelongToPlane;
1096 Class : BelongToCylinder_i
1097 Description : Verify whether mesh element lie in pointed Geom planar object
1100 BelongToCylinder_i::BelongToCylinder_i()
1101 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1105 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1107 BelongToSurface_i::SetSurface( theGeom, theType );
1108 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
1111 FunctorType BelongToCylinder_i::GetFunctorType()
1113 return FT_BelongToCylinder;
1117 Class : BelongToGenSurface_i
1118 Description : Verify whether mesh element lie in pointed Geom planar object
1121 BelongToGenSurface_i::BelongToGenSurface_i()
1122 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1126 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1128 if ( theGeom->_is_nil() )
1130 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1131 if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1132 aLocShape.Nullify();
1134 BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1135 TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1138 FunctorType BelongToGenSurface_i::GetFunctorType()
1140 return FT_BelongToGenSurface;
1144 Class : LyingOnGeom_i
1145 Description : Predicate for selection on geometrical support
1147 LyingOnGeom_i::LyingOnGeom_i()
1149 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1150 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1155 LyingOnGeom_i::~LyingOnGeom_i()
1161 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1163 if ( theGeom->_is_nil() )
1165 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1166 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1167 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1168 myLyingOnGeomPtr->SetGeom( aLocShape );
1169 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1172 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1174 myLyingOnGeomPtr->SetGeom( theShape );
1177 void LyingOnGeom_i::SetElementType(ElementType theType){
1178 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1179 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1182 FunctorType LyingOnGeom_i::GetFunctorType()
1184 return SMESH::FT_LyingOnGeom;
1187 void LyingOnGeom_i::SetShapeName( const char* theName )
1190 myShapeName = strdup( theName );
1191 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1192 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1195 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1198 myShapeName = strdup( theName );
1201 myShapeID = strdup( theID );
1205 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1206 myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
1208 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1211 char* LyingOnGeom_i::GetShapeName()
1213 return CORBA::string_dup( myShapeName );
1216 char* LyingOnGeom_i::GetShapeID()
1218 return CORBA::string_dup( myShapeID );
1221 void LyingOnGeom_i::SetTolerance( CORBA::Double theToler )
1223 myLyingOnGeomPtr->SetTolerance( theToler );
1224 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1227 CORBA::Double LyingOnGeom_i::GetTolerance()
1229 return myLyingOnGeomPtr->GetTolerance();
1233 Class : FreeBorders_i
1234 Description : Predicate for free borders
1236 FreeBorders_i::FreeBorders_i()
1238 myPredicatePtr.reset(new Controls::FreeBorders());
1239 myFunctorPtr = myPredicatePtr;
1242 FunctorType FreeBorders_i::GetFunctorType()
1244 return SMESH::FT_FreeBorders;
1249 Description : Predicate for free borders
1251 FreeEdges_i::FreeEdges_i()
1252 : myFreeEdgesPtr( new Controls::FreeEdges() )
1254 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1257 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1259 INFOS("FreeEdges_i::GetBorders");
1260 SMESH::Controls::FreeEdges::TBorders aBorders;
1261 myFreeEdgesPtr->GetBoreders( aBorders );
1263 long i = 0, iEnd = aBorders.size();
1265 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1266 aResult->length(iEnd);
1268 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1269 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1271 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1272 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1274 aBorder.myElemId = aBord.myElemId;
1275 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1276 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1279 INFOS("FreeEdges_i::GetBorders~");
1280 return aResult._retn();
1283 FunctorType FreeEdges_i::GetFunctorType()
1285 return SMESH::FT_FreeEdges;
1290 Description : Predicate for free faces
1292 FreeFaces_i::FreeFaces_i()
1294 myPredicatePtr.reset(new Controls::FreeFaces());
1295 myFunctorPtr = myPredicatePtr;
1298 FunctorType FreeFaces_i::GetFunctorType()
1300 return SMESH::FT_FreeFaces;
1305 Description : Predicate for free nodes
1307 FreeNodes_i::FreeNodes_i()
1309 myPredicatePtr.reset(new Controls::FreeNodes());
1310 myFunctorPtr = myPredicatePtr;
1313 FunctorType FreeNodes_i::GetFunctorType()
1315 return SMESH::FT_FreeNodes;
1319 Class : RangeOfIds_i
1320 Description : Predicate for Range of Ids.
1321 Range may be specified with two ways.
1322 1. Using AddToRange method
1323 2. With SetRangeStr method. Parameter of this method is a string
1324 like as "1,2,3,50-60,63,67,70-"
1327 RangeOfIds_i::RangeOfIds_i()
1329 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1330 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1333 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1335 CORBA::Long iEnd = theIds.length();
1336 for ( CORBA::Long i = 0; i < iEnd; i++ )
1337 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1338 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1341 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1343 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1344 return myRangeOfIdsPtr->SetRangeStr(
1345 TCollection_AsciiString( (Standard_CString)theRange ) );
1348 char* RangeOfIds_i::GetRangeStr()
1350 TCollection_AsciiString aStr;
1351 myRangeOfIdsPtr->GetRangeStr( aStr );
1352 return CORBA::string_dup( aStr.ToCString() );
1355 void RangeOfIds_i::SetElementType( ElementType theType )
1357 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1358 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1361 FunctorType RangeOfIds_i::GetFunctorType()
1363 return SMESH::FT_RangeOfIds;
1367 Class : LinearOrQuadratic_i
1368 Description : Predicate to verify whether a mesh element is linear
1370 LinearOrQuadratic_i::LinearOrQuadratic_i()
1372 myLinearOrQuadraticPtr.reset(new Controls::LinearOrQuadratic());
1373 myFunctorPtr = myPredicatePtr = myLinearOrQuadraticPtr;
1376 void LinearOrQuadratic_i::SetElementType(ElementType theType)
1378 myLinearOrQuadraticPtr->SetType(SMDSAbs_ElementType(theType));
1379 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1382 FunctorType LinearOrQuadratic_i::GetFunctorType()
1384 return SMESH::FT_LinearOrQuadratic;
1388 Class : GroupColor_i
1389 Description : Functor for check color of group to whic mesh element belongs to
1391 GroupColor_i::GroupColor_i()
1393 myGroupColorPtr.reset(new Controls::GroupColor());
1394 myFunctorPtr = myPredicatePtr = myGroupColorPtr;
1397 FunctorType GroupColor_i::GetFunctorType()
1399 return SMESH::FT_GroupColor;
1402 void GroupColor_i::SetColorStr( const char* theColor )
1404 myGroupColorPtr->SetColorStr(
1405 TCollection_AsciiString( (Standard_CString)theColor ) );
1406 TPythonDump()<<this<<".SetColorStr('"<<theColor<<"')";
1409 char* GroupColor_i::GetColorStr()
1411 TCollection_AsciiString aStr;
1412 myGroupColorPtr->GetColorStr( aStr );
1413 return CORBA::string_dup( aStr.ToCString() );
1416 void GroupColor_i::SetElementType(ElementType theType)
1418 myGroupColorPtr->SetType(SMDSAbs_ElementType(theType));
1419 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1423 Class : ElemGeomType_i
1424 Description : Predicate check is element has indicated geometry type
1426 ElemGeomType_i::ElemGeomType_i()
1428 myElemGeomTypePtr.reset(new Controls::ElemGeomType());
1429 myFunctorPtr = myPredicatePtr = myElemGeomTypePtr;
1432 void ElemGeomType_i::SetElementType(ElementType theType)
1434 myElemGeomTypePtr->SetType(SMDSAbs_ElementType(theType));
1435 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1438 void ElemGeomType_i::SetGeometryType(GeometryType theType)
1440 myElemGeomTypePtr->SetGeomType(SMDSAbs_GeometryType(theType));
1441 TPythonDump()<<this<<".SetGeometryType("<<theType<<")";
1444 GeometryType ElemGeomType_i::GetGeometryType() const
1446 return (GeometryType)myElemGeomTypePtr->GetGeomType();
1449 FunctorType ElemGeomType_i::GetFunctorType()
1451 return SMESH::FT_ElemGeomType;
1455 Class : CoplanarFaces_i
1456 Description : Returns true if a mesh face is a coplanar neighbour to a given one
1458 CoplanarFaces_i::CoplanarFaces_i()
1460 myCoplanarFacesPtr.reset(new Controls::CoplanarFaces());
1461 myFunctorPtr = myPredicatePtr = myCoplanarFacesPtr;
1464 void CoplanarFaces_i::SetFace ( CORBA::Long theFaceID )
1466 myCoplanarFacesPtr->SetFace(theFaceID);
1467 TPythonDump()<<this<<".SetFace("<<theFaceID<<")";
1470 void CoplanarFaces_i::SetTolerance( CORBA::Double theToler )
1472 myCoplanarFacesPtr->SetTolerance(theToler);
1473 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1476 CORBA::Long CoplanarFaces_i::GetFace () const
1478 return myCoplanarFacesPtr->GetFace();
1481 char* CoplanarFaces_i::GetFaceAsString () const
1483 TCollection_AsciiString str(Standard_Integer(myCoplanarFacesPtr->GetFace()));
1484 return CORBA::string_dup( str.ToCString() );
1487 CORBA::Double CoplanarFaces_i::GetTolerance() const
1489 return myCoplanarFacesPtr->GetTolerance();
1492 FunctorType CoplanarFaces_i::GetFunctorType()
1494 return SMESH::FT_CoplanarFaces;
1498 Class : Comparator_i
1499 Description : Base class for comparators
1501 Comparator_i::Comparator_i():
1502 myNumericalFunctor( NULL )
1505 Comparator_i::~Comparator_i()
1507 if ( myNumericalFunctor )
1508 myNumericalFunctor->Destroy();
1511 void Comparator_i::SetMargin( CORBA::Double theValue )
1513 myComparatorPtr->SetMargin( theValue );
1514 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1517 CORBA::Double Comparator_i::GetMargin()
1519 return myComparatorPtr->GetMargin();
1522 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1524 if ( myNumericalFunctor )
1525 myNumericalFunctor->Destroy();
1527 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1529 if ( myNumericalFunctor )
1531 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1532 myNumericalFunctor->Register();
1533 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1537 Controls::ComparatorPtr Comparator_i::GetComparator()
1539 return myComparatorPtr;
1542 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1544 return myNumericalFunctor;
1550 Description : Comparator "<"
1552 LessThan_i::LessThan_i()
1554 myComparatorPtr.reset( new Controls::LessThan() );
1555 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1558 FunctorType LessThan_i::GetFunctorType()
1560 return SMESH::FT_LessThan;
1566 Description : Comparator ">"
1568 MoreThan_i::MoreThan_i()
1570 myComparatorPtr.reset( new Controls::MoreThan() );
1571 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1574 FunctorType MoreThan_i::GetFunctorType()
1576 return SMESH::FT_MoreThan;
1582 Description : Comparator "="
1584 EqualTo_i::EqualTo_i()
1585 : myEqualToPtr( new Controls::EqualTo() )
1587 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1590 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1592 myEqualToPtr->SetTolerance( theToler );
1593 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1596 CORBA::Double EqualTo_i::GetTolerance()
1598 return myEqualToPtr->GetTolerance();
1601 FunctorType EqualTo_i::GetFunctorType()
1603 return SMESH::FT_EqualTo;
1607 Class : LogicalNOT_i
1608 Description : Logical NOT predicate
1610 LogicalNOT_i::LogicalNOT_i()
1611 : myPredicate( NULL ),
1612 myLogicalNOTPtr( new Controls::LogicalNOT() )
1614 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1617 LogicalNOT_i::~LogicalNOT_i()
1620 myPredicate->Destroy();
1623 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1626 myPredicate->Destroy();
1628 myPredicate = SMESH::GetPredicate(thePredicate);
1631 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1632 myPredicate->Register();
1633 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1637 FunctorType LogicalNOT_i::GetFunctorType()
1639 return SMESH::FT_LogicalNOT;
1642 Predicate_i* LogicalNOT_i::GetPredicate_i()
1649 Class : LogicalBinary_i
1650 Description : Base class for binary logical predicate
1652 LogicalBinary_i::LogicalBinary_i()
1653 : myPredicate1( NULL ),
1654 myPredicate2( NULL )
1657 LogicalBinary_i::~LogicalBinary_i()
1660 myPredicate1->Destroy();
1663 myPredicate2->Destroy();
1666 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1669 myPredicate1->SetMesh( theMesh );
1672 myPredicate2->SetMesh( theMesh );
1675 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1678 myPredicate1->Destroy();
1680 myPredicate1 = SMESH::GetPredicate(thePredicate);
1682 if ( myPredicate1 ){
1683 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1684 myPredicate1->Register();
1685 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1689 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1692 myPredicate2->Destroy();
1694 myPredicate2 = SMESH::GetPredicate(thePredicate);
1696 if ( myPredicate2 ){
1697 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1698 myPredicate2->Register();
1699 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1703 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1705 return myLogicalBinaryPtr;
1708 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1710 return myPredicate1;
1712 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1714 return myPredicate2;
1719 Class : LogicalAND_i
1720 Description : Logical AND
1722 LogicalAND_i::LogicalAND_i()
1724 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1725 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1728 FunctorType LogicalAND_i::GetFunctorType()
1730 return SMESH::FT_LogicalAND;
1736 Description : Logical OR
1738 LogicalOR_i::LogicalOR_i()
1740 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1741 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1744 FunctorType LogicalOR_i::GetFunctorType()
1746 return SMESH::FT_LogicalOR;
1754 FilterManager_i::FilterManager_i()
1755 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1757 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
1758 //PortableServer::ObjectId_var anObjectId =
1759 // SMESH_Gen_i::GetPOA()->activate_object( this );
1763 FilterManager_i::~FilterManager_i()
1765 //TPythonDump()<<this<<".Destroy()";
1769 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1771 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1772 SMESH::MinimumAngle_var anObj = aServant->_this();
1773 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1774 return anObj._retn();
1778 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1780 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1781 SMESH::AspectRatio_var anObj = aServant->_this();
1782 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1783 return anObj._retn();
1787 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1789 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1790 SMESH::AspectRatio3D_var anObj = aServant->_this();
1791 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1792 return anObj._retn();
1796 Warping_ptr FilterManager_i::CreateWarping()
1798 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1799 SMESH::Warping_var anObj = aServant->_this();
1800 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1801 return anObj._retn();
1805 Taper_ptr FilterManager_i::CreateTaper()
1807 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1808 SMESH::Taper_var anObj = aServant->_this();
1809 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1810 return anObj._retn();
1814 Skew_ptr FilterManager_i::CreateSkew()
1816 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1817 SMESH::Skew_var anObj = aServant->_this();
1818 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1819 return anObj._retn();
1823 Area_ptr FilterManager_i::CreateArea()
1825 SMESH::Area_i* aServant = new SMESH::Area_i();
1826 SMESH::Area_var anObj = aServant->_this();
1827 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1828 return anObj._retn();
1832 Volume3D_ptr FilterManager_i::CreateVolume3D()
1834 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
1835 SMESH::Volume3D_var anObj = aServant->_this();
1836 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
1837 return anObj._retn();
1841 Length_ptr FilterManager_i::CreateLength()
1843 SMESH::Length_i* aServant = new SMESH::Length_i();
1844 SMESH::Length_var anObj = aServant->_this();
1845 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1846 return anObj._retn();
1849 Length2D_ptr FilterManager_i::CreateLength2D()
1851 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1852 SMESH::Length2D_var anObj = aServant->_this();
1853 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1854 return anObj._retn();
1857 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1859 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1860 SMESH::MultiConnection_var anObj = aServant->_this();
1861 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1862 return anObj._retn();
1865 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1867 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1868 SMESH::MultiConnection2D_var anObj = aServant->_this();
1869 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
1870 return anObj._retn();
1873 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1875 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1876 SMESH::BelongToGeom_var anObj = aServant->_this();
1877 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
1878 return anObj._retn();
1881 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1883 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1884 SMESH::BelongToPlane_var anObj = aServant->_this();
1885 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
1886 return anObj._retn();
1889 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1891 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1892 SMESH::BelongToCylinder_var anObj = aServant->_this();
1893 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
1894 return anObj._retn();
1897 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
1899 SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
1900 SMESH::BelongToGenSurface_var anObj = aServant->_this();
1901 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
1902 return anObj._retn();
1905 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
1907 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
1908 SMESH::LyingOnGeom_var anObj = aServant->_this();
1909 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
1910 return anObj._retn();
1913 CoplanarFaces_ptr FilterManager_i::CreateCoplanarFaces()
1915 SMESH::CoplanarFaces_i* aServant = new SMESH::CoplanarFaces_i();
1916 SMESH::CoplanarFaces_var anObj = aServant->_this();
1917 TPythonDump()<<aServant<<" = "<<this<<".CreateCoplanarFaces()";
1918 return anObj._retn();
1921 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1923 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1924 SMESH::FreeBorders_var anObj = aServant->_this();
1925 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
1926 return anObj._retn();
1929 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1931 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1932 SMESH::FreeEdges_var anObj = aServant->_this();
1933 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
1934 return anObj._retn();
1937 FreeFaces_ptr FilterManager_i::CreateFreeFaces()
1939 SMESH::FreeFaces_i* aServant = new SMESH::FreeFaces_i();
1940 SMESH::FreeFaces_var anObj = aServant->_this();
1941 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeFaces()";
1942 return anObj._retn();
1945 FreeNodes_ptr FilterManager_i::CreateFreeNodes()
1947 SMESH::FreeNodes_i* aServant = new SMESH::FreeNodes_i();
1948 SMESH::FreeNodes_var anObj = aServant->_this();
1949 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeNodes()";
1950 return anObj._retn();
1953 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1955 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1956 SMESH::RangeOfIds_var anObj = aServant->_this();
1957 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
1958 return anObj._retn();
1961 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
1963 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
1964 SMESH::BadOrientedVolume_var anObj = aServant->_this();
1965 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
1966 return anObj._retn();
1969 LessThan_ptr FilterManager_i::CreateLessThan()
1971 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1972 SMESH::LessThan_var anObj = aServant->_this();
1973 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
1974 return anObj._retn();
1977 MoreThan_ptr FilterManager_i::CreateMoreThan()
1979 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1980 SMESH::MoreThan_var anObj = aServant->_this();
1981 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
1982 return anObj._retn();
1985 EqualTo_ptr FilterManager_i::CreateEqualTo()
1987 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1988 SMESH::EqualTo_var anObj = aServant->_this();
1989 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
1990 return anObj._retn();
1993 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1995 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1996 SMESH::LogicalNOT_var anObj = aServant->_this();
1997 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
1998 return anObj._retn();
2001 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
2003 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
2004 SMESH::LogicalAND_var anObj = aServant->_this();
2005 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
2006 return anObj._retn();
2009 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
2011 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
2012 SMESH::LogicalOR_var anObj = aServant->_this();
2013 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
2014 return anObj._retn();
2017 LinearOrQuadratic_ptr FilterManager_i::CreateLinearOrQuadratic()
2019 SMESH::LinearOrQuadratic_i* aServant = new SMESH::LinearOrQuadratic_i();
2020 SMESH::LinearOrQuadratic_var anObj = aServant->_this();
2021 TPythonDump()<<aServant<<" = "<<this<<".CreateLinearOrQuadratic()";
2022 return anObj._retn();
2025 GroupColor_ptr FilterManager_i::CreateGroupColor()
2027 SMESH::GroupColor_i* aServant = new SMESH::GroupColor_i();
2028 SMESH::GroupColor_var anObj = aServant->_this();
2029 TPythonDump()<<aServant<<" = "<<this<<".CreateGroupColor()";
2030 return anObj._retn();
2033 ElemGeomType_ptr FilterManager_i::CreateElemGeomType()
2035 SMESH::ElemGeomType_i* aServant = new SMESH::ElemGeomType_i();
2036 SMESH::ElemGeomType_var anObj = aServant->_this();
2037 TPythonDump()<<aServant<<" = "<<this<<".CreateElemGeomType()";
2038 return anObj._retn();
2041 Filter_ptr FilterManager_i::CreateFilter()
2043 SMESH::Filter_i* aServant = new SMESH::Filter_i();
2044 SMESH::Filter_var anObj = aServant->_this();
2045 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
2046 return anObj._retn();
2049 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
2051 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
2052 SMESH::FilterLibrary_var anObj = aServant->_this();
2053 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary('"<<aFileName<<"')";
2054 return anObj._retn();
2057 FilterLibrary_ptr FilterManager_i::CreateLibrary()
2059 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
2060 SMESH::FilterLibrary_var anObj = aServant->_this();
2061 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
2062 return anObj._retn();
2065 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
2067 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
2068 return remove( aFileName ) ? false : true;
2071 //=============================================================================
2073 * SMESH_Gen_i::CreateFilterManager
2075 * Create filter manager
2077 //=============================================================================
2079 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
2081 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2082 SMESH::FilterManager_var anObj = aFilter->_this();
2083 return anObj._retn();
2091 //=======================================================================
2092 // name : Filter_i::Filter_i
2093 // Purpose : Constructor
2094 //=======================================================================
2095 Filter_i::Filter_i()
2096 : myPredicate( NULL )
2099 //=======================================================================
2100 // name : Filter_i::~Filter_i
2101 // Purpose : Destructor
2102 //=======================================================================
2103 Filter_i::~Filter_i()
2106 myPredicate->Destroy();
2108 if(!CORBA::is_nil(myMesh))
2111 //TPythonDump()<<this<<".Destroy()";
2114 //=======================================================================
2115 // name : Filter_i::SetPredicate
2116 // Purpose : Set predicate
2117 //=======================================================================
2118 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
2121 myPredicate->Destroy();
2123 myPredicate = SMESH::GetPredicate(thePredicate);
2127 myFilter.SetPredicate( myPredicate->GetPredicate() );
2128 myPredicate->Register();
2129 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
2133 //=======================================================================
2134 // name : Filter_i::GetElementType
2135 // Purpose : Get entity type
2136 //=======================================================================
2137 SMESH::ElementType Filter_i::GetElementType()
2139 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
2142 //=======================================================================
2143 // name : Filter_i::SetMesh
2144 // Purpose : Set mesh
2145 //=======================================================================
2148 SetMesh( SMESH_Mesh_ptr theMesh )
2150 if(!CORBA::is_nil(theMesh))
2151 theMesh->Register();
2153 if(!CORBA::is_nil(myMesh))
2156 myMesh = SMESH_Mesh::_duplicate( theMesh );
2157 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
2164 return GetElementsId(myMesh);
2167 //=======================================================================
2168 // name : Filter_i::GetElementsId
2169 // Purpose : Get ids of entities
2170 //=======================================================================
2173 GetElementsId( Predicate_i* thePredicate,
2174 const SMDS_Mesh* theMesh,
2175 Controls::Filter::TIdSequence& theSequence )
2178 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
2183 GetElementsId( Predicate_i* thePredicate,
2184 SMESH_Mesh_ptr theMesh,
2185 Controls::Filter::TIdSequence& theSequence )
2188 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2189 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
2194 GetElementsId( SMESH_Mesh_ptr theMesh )
2196 SMESH::long_array_var anArray = new SMESH::long_array;
2197 if(!CORBA::is_nil(theMesh) && myPredicate){
2198 Controls::Filter::TIdSequence aSequence;
2199 GetElementsId(myPredicate,theMesh,aSequence);
2200 long i = 0, iEnd = aSequence.size();
2201 anArray->length( iEnd );
2202 for ( ; i < iEnd; i++ )
2203 anArray[ i ] = aSequence[i];
2205 return anArray._retn();
2208 template<class TElement, class TIterator, class TPredicate>
2209 static void collectMeshInfo(const TIterator& theItr,
2210 TPredicate& thePred,
2211 SMESH::long_array& theRes)
2215 while (theItr->more()) {
2216 const SMDS_MeshElement* anElem = theItr->next();
2217 if ( thePred->IsSatisfy( anElem->GetID() ) )
2218 theRes[ anElem->GetEntityType() ]++;
2222 //=============================================================================
2224 * \brief Returns statistic of mesh elements
2226 //=============================================================================
2227 SMESH::long_array* ::Filter_i::GetMeshInfo()
2229 SMESH::long_array_var aRes = new SMESH::long_array();
2230 aRes->length(SMESH::Entity_Last);
2231 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
2234 if(!CORBA::is_nil(myMesh) && myPredicate) {
2235 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2236 SMDS_ElemIteratorPtr it;
2237 switch( GetElementType() )
2240 collectMeshInfo<const SMDS_MeshNode*>(aMesh->nodesIterator(),myPredicate,aRes);
2243 collectMeshInfo<const SMDS_MeshElement*>(aMesh->edgesIterator(),myPredicate,aRes);
2246 collectMeshInfo<const SMDS_MeshElement*>(aMesh->facesIterator(),myPredicate,aRes);
2248 case SMDSAbs_Volume:
2249 collectMeshInfo<const SMDS_MeshElement*>(aMesh->volumesIterator(),myPredicate,aRes);
2253 collectMeshInfo<const SMDS_MeshElement*>(aMesh->elementsIterator(),myPredicate,aRes);
2259 return aRes._retn();
2262 //================================================================================
2264 * \brief Return GetElementType() within an array
2265 * Implement SMESH_IDSource interface
2267 //================================================================================
2269 SMESH::array_of_ElementType* Filter_i::GetTypes()
2271 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
2273 types[0] = GetElementType();
2274 return types._retn();
2277 //=======================================================================
2278 // name : getCriteria
2279 // Purpose : Retrieve criterions from predicate
2280 //=======================================================================
2281 static inline bool getCriteria( Predicate_i* thePred,
2282 SMESH::Filter::Criteria_out theCriteria )
2284 int aFType = thePred->GetFunctorType();
2288 case FT_FreeBorders:
2291 case FT_LinearOrQuadratic:
2294 CORBA::ULong i = theCriteria->length();
2295 theCriteria->length( i + 1 );
2297 theCriteria[ i ] = createCriterion();
2299 theCriteria[ i ].Type = aFType;
2300 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
2303 case FT_BelongToGeom:
2305 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
2307 CORBA::ULong i = theCriteria->length();
2308 theCriteria->length( i + 1 );
2310 theCriteria[ i ] = createCriterion();
2312 theCriteria[ i ].Type = FT_BelongToGeom;
2313 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2314 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2315 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2316 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2320 case FT_BelongToPlane:
2321 case FT_BelongToCylinder:
2322 case FT_BelongToGenSurface:
2324 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
2326 CORBA::ULong i = theCriteria->length();
2327 theCriteria->length( i + 1 );
2329 theCriteria[ i ] = createCriterion();
2331 theCriteria[ i ].Type = aFType;
2332 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2333 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2334 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2335 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2339 case FT_LyingOnGeom:
2341 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
2343 CORBA::ULong i = theCriteria->length();
2344 theCriteria->length( i + 1 );
2346 theCriteria[ i ] = createCriterion();
2348 theCriteria[ i ].Type = FT_LyingOnGeom;
2349 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2350 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2351 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2352 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2356 case FT_CoplanarFaces:
2358 CoplanarFaces_i* aPred = dynamic_cast<CoplanarFaces_i*>( thePred );
2360 CORBA::ULong i = theCriteria->length();
2361 theCriteria->length( i + 1 );
2363 theCriteria[ i ] = createCriterion();
2364 CORBA::String_var faceId = aPred->GetFaceAsString();
2366 theCriteria[ i ].Type = FT_CoplanarFaces;
2367 theCriteria[ i ].ThresholdID = faceId;
2368 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2374 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
2376 CORBA::ULong i = theCriteria->length();
2377 theCriteria->length( i + 1 );
2379 theCriteria[ i ] = createCriterion();
2381 theCriteria[ i ].Type = FT_RangeOfIds;
2382 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
2383 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2387 case FT_BadOrientedVolume:
2389 BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
2391 CORBA::ULong i = theCriteria->length();
2392 theCriteria->length( i + 1 );
2394 theCriteria[ i ] = createCriterion();
2396 theCriteria[ i ].Type = FT_BadOrientedVolume;
2397 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2405 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
2407 CORBA::ULong i = theCriteria->length();
2408 theCriteria->length( i + 1 );
2410 theCriteria[ i ] = createCriterion();
2412 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
2413 theCriteria[ i ].Compare = aFType;
2414 theCriteria[ i ].Threshold = aCompar->GetMargin();
2415 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
2417 if ( aFType == FT_EqualTo )
2419 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
2420 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
2427 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2428 getCriteria( aPred, theCriteria );
2429 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2436 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2437 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2438 if ( !getCriteria( aPred1, theCriteria ) )
2440 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2441 return getCriteria( aPred2, theCriteria );
2445 CORBA::ULong i = theCriteria->length();
2446 theCriteria->length( i + 1 );
2448 theCriteria[ i ] = createCriterion();
2450 GroupColor_i* aPred = dynamic_cast<GroupColor_i*>( thePred );
2451 theCriteria[ i ].Type = aFType;
2452 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2453 theCriteria[ i ].ThresholdStr = aPred->GetColorStr();
2457 case FT_ElemGeomType:
2459 CORBA::ULong i = theCriteria->length();
2460 theCriteria->length( i + 1 );
2462 theCriteria[ i ] = createCriterion();
2464 ElemGeomType_i* aPred = dynamic_cast<ElemGeomType_i*>( thePred );
2465 theCriteria[ i ].Type = aFType;
2466 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2467 theCriteria[ i ].Threshold = (double)aPred->GetGeometryType();
2478 //=======================================================================
2479 // name : Filter_i::GetCriteria
2480 // Purpose : Retrieve criterions from predicate
2481 //=======================================================================
2482 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2484 theCriteria = new SMESH::Filter::Criteria;
2485 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2488 //=======================================================================
2489 // name : Filter_i::SetCriteria
2490 // Purpose : Create new predicate and set criterions in it
2491 //=======================================================================
2492 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2494 if ( myPredicate != 0 )
2495 myPredicate->Destroy();
2497 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2498 FilterManager_ptr aFilterMgr = aFilter->_this();
2500 // CREATE two lists ( PREDICATES and LOG OP )
2503 TPythonDump()<<"aCriteria = []";
2504 std::list<SMESH::Predicate_ptr> aPredicates;
2505 std::list<int> aBinaries;
2506 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2508 int aCriterion = theCriteria[ i ].Type;
2509 int aCompare = theCriteria[ i ].Compare;
2510 double aThreshold = theCriteria[ i ].Threshold;
2511 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2512 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2513 int aUnary = theCriteria[ i ].UnaryOp;
2514 int aBinary = theCriteria[ i ].BinaryOp;
2515 double aTolerance = theCriteria[ i ].Tolerance;
2516 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
2517 long aPrecision = theCriteria[ i ].Precision;
2521 pd << "aCriterion = SMESH.Filter.Criterion(" << aCriterion << "," << aCompare
2522 << "," << aThreshold << ",'" << aThresholdStr;
2523 if (aThresholdID && strlen(aThresholdID))
2524 //pd << "',salome.ObjectToID(" << aThresholdID
2525 pd << "','" << aThresholdID
2526 << "'," << aUnary << "," << aBinary << "," << aTolerance
2527 << "," << aTypeOfElem << "," << aPrecision << ")";
2529 pd << "',''," << aUnary << "," << aBinary << "," << aTolerance
2530 << "," << aTypeOfElem << "," << aPrecision << ")";
2533 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2534 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2536 switch ( aCriterion )
2540 case SMESH::FT_MultiConnection:
2541 aFunctor = aFilterMgr->CreateMultiConnection();
2543 case SMESH::FT_MultiConnection2D:
2544 aFunctor = aFilterMgr->CreateMultiConnection2D();
2546 case SMESH::FT_Length:
2547 aFunctor = aFilterMgr->CreateLength();
2549 case SMESH::FT_Length2D:
2550 aFunctor = aFilterMgr->CreateLength2D();
2552 case SMESH::FT_AspectRatio:
2553 aFunctor = aFilterMgr->CreateAspectRatio();
2555 case SMESH::FT_AspectRatio3D:
2556 aFunctor = aFilterMgr->CreateAspectRatio3D();
2558 case SMESH::FT_Warping:
2559 aFunctor = aFilterMgr->CreateWarping();
2561 case SMESH::FT_MinimumAngle:
2562 aFunctor = aFilterMgr->CreateMinimumAngle();
2564 case SMESH::FT_Taper:
2565 aFunctor = aFilterMgr->CreateTaper();
2567 case SMESH::FT_Skew:
2568 aFunctor = aFilterMgr->CreateSkew();
2570 case SMESH::FT_Area:
2571 aFunctor = aFilterMgr->CreateArea();
2573 case SMESH::FT_Volume3D:
2574 aFunctor = aFilterMgr->CreateVolume3D();
2579 case SMESH::FT_FreeBorders:
2580 aPredicate = aFilterMgr->CreateFreeBorders();
2582 case SMESH::FT_FreeEdges:
2583 aPredicate = aFilterMgr->CreateFreeEdges();
2585 case SMESH::FT_FreeFaces:
2586 aPredicate = aFilterMgr->CreateFreeFaces();
2588 case SMESH::FT_FreeNodes:
2589 aPredicate = aFilterMgr->CreateFreeNodes();
2591 case SMESH::FT_BelongToGeom:
2593 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2594 tmpPred->SetElementType( aTypeOfElem );
2595 tmpPred->SetShape( aThresholdID, aThresholdStr );
2596 tmpPred->SetTolerance( aTolerance );
2597 aPredicate = tmpPred;
2600 case SMESH::FT_BelongToPlane:
2601 case SMESH::FT_BelongToCylinder:
2602 case SMESH::FT_BelongToGenSurface:
2604 SMESH::BelongToSurface_ptr tmpPred;
2605 switch ( aCriterion ) {
2606 case SMESH::FT_BelongToPlane:
2607 tmpPred = aFilterMgr->CreateBelongToPlane(); break;
2608 case SMESH::FT_BelongToCylinder:
2609 tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
2611 tmpPred = aFilterMgr->CreateBelongToGenSurface();
2613 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2614 tmpPred->SetTolerance( aTolerance );
2615 aPredicate = tmpPred;
2618 case SMESH::FT_LyingOnGeom:
2620 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2621 tmpPred->SetElementType( aTypeOfElem );
2622 tmpPred->SetShape( aThresholdID, aThresholdStr );
2623 tmpPred->SetTolerance( aTolerance );
2624 aPredicate = tmpPred;
2627 case SMESH::FT_RangeOfIds:
2629 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2630 tmpPred->SetRangeStr( aThresholdStr );
2631 tmpPred->SetElementType( aTypeOfElem );
2632 aPredicate = tmpPred;
2635 case SMESH::FT_BadOrientedVolume:
2637 aPredicate = aFilterMgr->CreateBadOrientedVolume();
2640 case SMESH::FT_LinearOrQuadratic:
2642 SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
2643 tmpPred->SetElementType( aTypeOfElem );
2644 aPredicate = tmpPred;
2647 case SMESH::FT_GroupColor:
2649 SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor();
2650 tmpPred->SetElementType( aTypeOfElem );
2651 tmpPred->SetColorStr( aThresholdStr );
2652 aPredicate = tmpPred;
2655 case SMESH::FT_ElemGeomType:
2657 SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType();
2658 tmpPred->SetElementType( aTypeOfElem );
2659 tmpPred->SetGeometryType( (GeometryType)(int)(aThreshold + 0.5) );
2660 aPredicate = tmpPred;
2663 case SMESH::FT_CoplanarFaces:
2665 SMESH::CoplanarFaces_ptr tmpPred = aFilterMgr->CreateCoplanarFaces();
2666 tmpPred->SetFace( atol (aThresholdID ));
2667 tmpPred->SetTolerance( aTolerance );
2668 aPredicate = tmpPred;
2677 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
2679 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
2681 if ( aCompare == SMESH::FT_LessThan )
2682 aComparator = aFilterMgr->CreateLessThan();
2683 else if ( aCompare == SMESH::FT_MoreThan )
2684 aComparator = aFilterMgr->CreateMoreThan();
2685 else if ( aCompare == SMESH::FT_EqualTo )
2686 aComparator = aFilterMgr->CreateEqualTo();
2690 aComparator->SetNumFunctor( aFunctor );
2691 aComparator->SetMargin( aThreshold );
2693 if ( aCompare == FT_EqualTo )
2695 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
2696 anEqualTo->SetTolerance( aTolerance );
2699 aPredicate = aComparator;
2701 aFunctor->SetPrecision( aPrecision );
2705 if ( aUnary == FT_LogicalNOT )
2707 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
2708 aNotPred->SetPredicate( aPredicate );
2709 aPredicate = aNotPred;
2713 aPredicates.push_back( aPredicate );
2714 aBinaries.push_back( aBinary );
2715 TPythonDump()<<"aCriteria.append(aCriterion)";
2718 TPythonDump()<<this<<".SetCriteria(aCriteria)";
2720 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
2722 // combine all "AND" operations
2724 std::list<SMESH::Predicate_ptr> aResList;
2726 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
2727 std::list<int>::iterator aBinaryIter;
2729 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
2730 int aPrevBinary = SMESH::FT_Undefined;
2732 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
2733 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
2734 ++aPredIter, ++aBinaryIter )
2736 int aCurrBinary = *aBinaryIter;
2738 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
2740 if ( aPrevBinary == SMESH::FT_LogicalAND )
2743 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2744 aBinaryPred->SetPredicate1( aPrevPredicate );
2745 aBinaryPred->SetPredicate2( *aPredIter );
2746 aCurrPred = aBinaryPred;
2749 aCurrPred = *aPredIter;
2751 if ( aCurrBinary != SMESH::FT_LogicalAND )
2752 aResList.push_back( aCurrPred );
2754 aPrevPredicate = aCurrPred;
2755 aPrevBinary = aCurrBinary;
2758 // combine all "OR" operations
2760 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2762 if ( aResList.size() == 1 )
2763 aResPredicate = *aResList.begin();
2764 else if ( aResList.size() > 1 )
2766 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2767 aResPredicate = *anIter;
2769 for ( ; anIter != aResList.end(); ++anIter )
2771 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2772 aBinaryPred->SetPredicate1( aResPredicate );
2773 aBinaryPred->SetPredicate2( *anIter );
2774 aResPredicate = aBinaryPred;
2778 SetPredicate( aResPredicate );
2780 return !aResPredicate->_is_nil();
2783 //=======================================================================
2784 // name : Filter_i::GetPredicate_i
2785 // Purpose : Get implementation of predicate
2786 //=======================================================================
2787 Predicate_i* Filter_i::GetPredicate_i()
2792 //=======================================================================
2793 // name : Filter_i::GetPredicate
2794 // Purpose : Get predicate
2795 //=======================================================================
2796 Predicate_ptr Filter_i::GetPredicate()
2798 if ( myPredicate == 0 )
2799 return SMESH::Predicate::_nil();
2802 SMESH::Predicate_var anObj = myPredicate->_this();
2803 return anObj._retn();
2811 #define ATTR_TYPE "type"
2812 #define ATTR_COMPARE "compare"
2813 #define ATTR_THRESHOLD "threshold"
2814 #define ATTR_UNARY "unary"
2815 #define ATTR_BINARY "binary"
2816 #define ATTR_THRESHOLD_STR "threshold_str"
2817 #define ATTR_TOLERANCE "tolerance"
2818 #define ATTR_ELEMENT_TYPE "ElementType"
2820 //=======================================================================
2822 // Purpose : Convert bool to LDOMString
2823 //=======================================================================
2824 static inline LDOMString toString( CORBA::Boolean val )
2826 return val ? "logical not" : "";
2829 //=======================================================================
2831 // Purpose : Convert LDOMString to bool
2832 //=======================================================================
2833 static inline bool toBool( const LDOMString& theStr )
2835 return theStr.equals( "logical not" );
2838 //=======================================================================
2840 // Purpose : Convert double to LDOMString
2841 //=======================================================================
2842 static inline LDOMString toString( CORBA::Double val )
2845 sprintf( a, "%e", val );
2846 return LDOMString( a );
2849 //=======================================================================
2851 // Purpose : Convert LDOMString to double
2852 //=======================================================================
2853 static inline double toDouble( const LDOMString& theStr )
2855 return atof( theStr.GetString() );
2858 //=======================================================================
2860 // Purpose : Convert functor type to LDOMString
2861 //=======================================================================
2862 static inline LDOMString toString( CORBA::Long theType )
2866 case FT_AspectRatio : return "Aspect ratio";
2867 case FT_Warping : return "Warping";
2868 case FT_MinimumAngle : return "Minimum angle";
2869 case FT_Taper : return "Taper";
2870 case FT_Skew : return "Skew";
2871 case FT_Area : return "Area";
2872 case FT_Volume3D : return "Volume3D";
2873 case FT_BelongToGeom : return "Belong to Geom";
2874 case FT_BelongToPlane : return "Belong to Plane";
2875 case FT_BelongToCylinder: return "Belong to Cylinder";
2876 case FT_BelongToGenSurface: return "Belong to Generic Surface";
2877 case FT_LyingOnGeom : return "Lying on Geom";
2878 case FT_BadOrientedVolume: return "Bad Oriented Volume";
2879 case FT_RangeOfIds : return "Range of IDs";
2880 case FT_FreeBorders : return "Free borders";
2881 case FT_FreeEdges : return "Free edges";
2882 case FT_FreeFaces : return "Free faces";
2883 case FT_FreeNodes : return "Free nodes";
2884 case FT_MultiConnection : return "Borders at multi-connections";
2885 case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2886 case FT_Length : return "Length";
2887 case FT_Length2D : return "Length 2D";
2888 case FT_LessThan : return "Less than";
2889 case FT_MoreThan : return "More than";
2890 case FT_EqualTo : return "Equal to";
2891 case FT_LogicalNOT : return "Not";
2892 case FT_LogicalAND : return "And";
2893 case FT_LogicalOR : return "Or";
2894 case FT_GroupColor : return "Color of Group";
2895 case FT_LinearOrQuadratic : return "Linear or Quadratic";
2896 case FT_ElemGeomType : return "Element geomtry type";
2897 case FT_Undefined : return "";
2898 default : return "";
2902 //=======================================================================
2903 // name : toFunctorType
2904 // Purpose : Convert LDOMString to functor type
2905 //=======================================================================
2906 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
2908 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
2909 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
2910 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
2911 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
2912 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
2913 else if ( theStr.equals( "Area" ) ) return FT_Area;
2914 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
2915 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
2916 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
2917 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
2918 else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface;
2919 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
2920 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
2921 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
2922 else if ( theStr.equals( "Free faces" ) ) return FT_FreeFaces;
2923 else if ( theStr.equals( "Free nodes" ) ) return FT_FreeNodes;
2924 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
2925 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
2926 else if ( theStr.equals( "Length" ) ) return FT_Length;
2927 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
2928 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
2929 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
2930 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
2931 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
2932 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
2933 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
2934 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
2935 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
2936 else if ( theStr.equals( "Color of Group" ) ) return FT_GroupColor;
2937 else if ( theStr.equals( "Linear or Quadratic" ) ) return FT_LinearOrQuadratic;
2938 else if ( theStr.equals( "Element geomtry type" ) ) return FT_ElemGeomType;
2939 else if ( theStr.equals( "" ) ) return FT_Undefined;
2940 else return FT_Undefined;
2943 //=======================================================================
2944 // name : toFunctorType
2945 // Purpose : Convert LDOMString to value of ElementType enumeration
2946 //=======================================================================
2947 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
2949 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
2950 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
2951 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
2952 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
2953 else return SMESH::ALL;
2956 //=======================================================================
2958 // Purpose : Convert ElementType to string
2959 //=======================================================================
2960 static inline LDOMString toString( const SMESH::ElementType theType )
2964 case SMESH::NODE : return "NODE";
2965 case SMESH::EDGE : return "EDGE";
2966 case SMESH::FACE : return "FACE";
2967 case SMESH::VOLUME : return "VOLUME";
2968 case SMESH::ALL : return "ALL";
2969 default : return "";
2973 //=======================================================================
2974 // name : findFilter
2975 // Purpose : Find filter in document
2976 //=======================================================================
2977 static LDOM_Element findFilter( const char* theFilterName,
2978 const LDOM_Document& theDoc,
2979 LDOM_Node* theParent = 0 )
2981 LDOM_Element aRootElement = theDoc.getDocumentElement();
2982 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
2983 return LDOM_Element();
2985 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
2986 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
2988 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
2989 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2991 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
2992 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
2993 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
2995 if ( theParent != 0 )
2996 *theParent = aTypeNode;
2997 return (LDOM_Element&)aFilter;
3001 return LDOM_Element();
3004 //=======================================================================
3005 // name : getSectionName
3006 // Purpose : Get name of section of filters
3007 //=======================================================================
3008 static const char* getSectionName( const ElementType theType )
3012 case SMESH::NODE : return "Filters for nodes";
3013 case SMESH::EDGE : return "Filters for edges";
3014 case SMESH::FACE : return "Filters for faces";
3015 case SMESH::VOLUME : return "Filters for volumes";
3016 case SMESH::ALL : return "Filters for elements";
3017 default : return "";
3021 //=======================================================================
3022 // name : getSection
3023 // Purpose : Create section for filters corresponding to the entity type
3024 //=======================================================================
3025 static LDOM_Node getSection( const ElementType theType,
3026 LDOM_Document& theDoc,
3027 const bool toCreate = false )
3029 LDOM_Element aRootElement = theDoc.getDocumentElement();
3030 if ( aRootElement.isNull() )
3034 bool anExist = false;
3035 const char* aSectionName = getSectionName( theType );
3036 if ( strcmp( aSectionName, "" ) == 0 )
3039 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
3041 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
3043 aNode = aSections.item( i );
3044 LDOM_Element& anItem = ( LDOM_Element& )aNode;
3045 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
3052 // Create new section if necessary
3057 LDOM_Element aNewItem = theDoc.createElement( "section" );
3058 aNewItem.setAttribute( "name", aSectionName );
3059 aRootElement.appendChild( aNewItem );
3069 //=======================================================================
3070 // name : createFilterItem
3071 // Purpose : Create filter item or LDOM document
3072 //=======================================================================
3073 static LDOM_Element createFilterItem( const char* theName,
3074 SMESH::Filter_ptr theFilter,
3075 LDOM_Document& theDoc )
3077 // create new filter in document
3078 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
3079 aFilterItem.setAttribute( "name", theName );
3081 // save filter criterions
3082 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3084 if ( !theFilter->GetCriteria( aCriteria ) )
3085 return LDOM_Element();
3087 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
3089 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
3091 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
3092 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
3093 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
3094 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
3095 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
3097 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
3098 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
3099 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
3100 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
3102 aFilterItem.appendChild( aCriterionItem );
3108 //=======================================================================
3109 // name : FilterLibrary_i::FilterLibrary_i
3110 // Purpose : Constructor
3111 //=======================================================================
3112 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
3114 myFileName = strdup( theFileName );
3115 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
3116 myFilterMgr = aFilterMgr->_this();
3120 // Try to use existing library file
3121 bool anExists = false;
3122 if ( !aParser.parse( myFileName ) )
3124 myDoc = aParser.getDocument();
3127 // Create a new XML document if it doesn't exist
3129 myDoc = LDOM_Document::createDocument( LDOMString() );
3131 LDOM_Element aRootElement = myDoc.getDocumentElement();
3132 if ( aRootElement.isNull() )
3134 // If the existing document is empty --> try to create a new one
3136 myDoc = LDOM_Document::createDocument( LDOMString() );
3140 //=======================================================================
3141 // name : FilterLibrary_i::FilterLibrary_i
3142 // Purpose : Constructor
3143 //=======================================================================
3144 FilterLibrary_i::FilterLibrary_i()
3147 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
3148 myFilterMgr = aFilter->_this();
3150 myDoc = LDOM_Document::createDocument( LDOMString() );
3153 FilterLibrary_i::~FilterLibrary_i()
3156 //TPythonDump()<<this<<".Destroy()";
3159 //=======================================================================
3160 // name : FilterLibrary_i::Copy
3161 // Purpose : Create filter and initialize it with values from library
3162 //=======================================================================
3163 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
3165 Filter_ptr aRes = Filter::_nil();
3166 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
3168 if ( aFilter.isNull() )
3171 std::list<SMESH::Filter::Criterion> aCriteria;
3173 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
3174 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
3176 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
3178 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
3179 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
3180 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
3181 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
3182 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
3184 SMESH::Filter::Criterion aCriterion = createCriterion();
3186 aCriterion.Type = toFunctorType( aTypeStr );
3187 aCriterion.Compare = toFunctorType( aCompareStr );
3188 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
3189 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
3191 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
3193 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
3195 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3196 ? val : atof( str.GetString() );
3198 str = aCrit->getAttribute( ATTR_TOLERANCE );
3199 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3200 ? val : atof( str.GetString() );
3202 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
3203 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
3206 sprintf( a, "%d", val );
3207 aCriterion.ThresholdStr = strdup( a );
3210 aCriterion.ThresholdStr = str.GetString();
3212 aCriteria.push_back( aCriterion );
3215 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
3216 aCriteriaVar->length( aCriteria.size() );
3219 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
3221 for( ; anIter != aCriteria.end(); ++anIter )
3222 aCriteriaVar[ i++ ] = *anIter;
3224 aRes = myFilterMgr->CreateFilter();
3225 aRes->SetCriteria( aCriteriaVar.inout() );
3227 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
3232 //=======================================================================
3233 // name : FilterLibrary_i::SetFileName
3234 // Purpose : Set file name for library
3235 //=======================================================================
3236 void FilterLibrary_i::SetFileName( const char* theFileName )
3239 myFileName = strdup( theFileName );
3240 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
3243 //=======================================================================
3244 // name : FilterLibrary_i::GetFileName
3245 // Purpose : Get file name of library
3246 //=======================================================================
3247 char* FilterLibrary_i::GetFileName()
3249 return CORBA::string_dup( myFileName );
3252 //=======================================================================
3253 // name : FilterLibrary_i::Add
3254 // Purpose : Add new filter to library
3255 //=======================================================================
3256 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
3258 // if filter already in library or entry filter is null do nothing
3259 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3260 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
3263 // get section corresponding to the filter type
3264 ElementType anEntType = theFilter->GetElementType();
3266 LDOM_Node aSection = getSection( anEntType, myDoc, true );
3267 if ( aSection.isNull() )
3270 // create filter item
3271 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
3272 if ( aFilterItem.isNull() )
3276 aSection.appendChild( aFilterItem );
3277 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3278 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
3283 //=======================================================================
3284 // name : FilterLibrary_i::Add
3285 // Purpose : Add new filter to library
3286 //=======================================================================
3287 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
3289 // if filter already in library or entry filter is null do nothing
3290 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3291 if ( !aFilterNode.isNull() )
3294 LDOM_Node aSection = getSection( theType, myDoc, true );
3295 if ( aSection.isNull() )
3298 // create filter item
3299 Filter_var aFilter = myFilterMgr->CreateFilter();
3301 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
3302 if ( aFilterItem.isNull() )
3306 aSection.appendChild( aFilterItem );
3307 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
3312 //=======================================================================
3313 // name : FilterLibrary_i::Delete
3314 // Purpose : Delete filter from library
3315 //=======================================================================
3316 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
3318 LDOM_Node aParentNode;
3319 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
3320 if ( aFilterNode.isNull() || aParentNode.isNull() )
3323 aParentNode.removeChild( aFilterNode );
3324 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
3328 //=======================================================================
3329 // name : FilterLibrary_i::Replace
3330 // Purpose : Replace existing filter with entry filter.
3331 // IMPORTANT : If filter does not exist it is not created
3332 //=======================================================================
3333 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
3334 const char* theNewName,
3335 Filter_ptr theFilter )
3337 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
3338 if ( aFilterItem.isNull() || theFilter->_is_nil() )
3341 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
3342 if ( aNewItem.isNull() )
3346 aFilterItem.ReplaceElement( aNewItem );
3347 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3348 TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
3353 //=======================================================================
3354 // name : FilterLibrary_i::Save
3355 // Purpose : Save library on disk
3356 //=======================================================================
3357 CORBA::Boolean FilterLibrary_i::Save()
3359 if ( myFileName == 0 || strlen( myFileName ) == 0 )
3362 FILE* aOutFile = fopen( myFileName, "wt" );
3366 LDOM_XmlWriter aWriter( aOutFile );
3367 aWriter.SetIndentation( 2 );
3371 TPythonDump()<<this<<".Save()";
3375 //=======================================================================
3376 // name : FilterLibrary_i::SaveAs
3377 // Purpose : Save library on disk
3378 //=======================================================================
3379 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
3381 myFileName = strdup ( aFileName );
3382 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
3386 //=======================================================================
3387 // name : FilterLibrary_i::IsPresent
3388 // Purpose : Verify whether filter is in library
3389 //=======================================================================
3390 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
3392 return !findFilter( theFilterName, myDoc ).isNull();
3395 //=======================================================================
3396 // name : FilterLibrary_i::NbFilters
3397 // Purpose : Return amount of filters in library
3398 //=======================================================================
3399 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
3401 string_array_var aNames = GetNames( theType );
3402 return aNames->length();
3405 //=======================================================================
3406 // name : FilterLibrary_i::GetNames
3407 // Purpose : Get names of filters from library
3408 //=======================================================================
3409 string_array* FilterLibrary_i::GetNames( ElementType theType )
3411 string_array_var anArray = new string_array;
3412 TColStd_SequenceOfHAsciiString aSeq;
3414 LDOM_Node aSection = getSection( theType, myDoc, false );
3416 if ( !aSection.isNull() )
3418 for ( LDOM_Node aFilter = aSection.getFirstChild();
3419 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3421 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
3422 aSeq.Append( new TCollection_HAsciiString(
3423 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
3427 anArray->length( aSeq.Length() );
3428 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
3429 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
3431 return anArray._retn();
3434 //=======================================================================
3435 // name : FilterLibrary_i::GetAllNames
3436 // Purpose : Get names of filters from library
3437 //=======================================================================
3438 string_array* FilterLibrary_i::GetAllNames()
3440 string_array_var aResArray = new string_array;
3441 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
3443 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
3445 int aPrevLength = aResArray->length();
3446 aResArray->length( aPrevLength + aNames->length() );
3447 for ( int i = 0, n = aNames->length(); i < n; i++ )
3448 aResArray[ aPrevLength + i ] = aNames[ i ];
3451 return aResArray._retn();