1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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 "SMDS_ElemIterator.hxx"
31 #include "SMDS_Mesh.hxx"
32 #include "SMDS_MeshElement.hxx"
33 #include "SMDS_MeshNode.hxx"
34 #include "SMESHDS_Mesh.hxx"
35 #include "SMESH_Gen_i.hxx"
36 #include "SMESH_Group_i.hxx"
37 #include "SMESH_PythonDump.hxx"
39 #include <SALOMEDS_wrap.hxx>
40 #include <GEOM_wrap.hxx>
42 #include <BRep_Tool.hxx>
43 #include <Geom_CylindricalSurface.hxx>
44 #include <Geom_Plane.hxx>
45 #include <LDOMParser.hxx>
46 #include <LDOMString.hxx>
47 #include <LDOM_Document.hxx>
48 #include <LDOM_Element.hxx>
49 #include <LDOM_Node.hxx>
50 #include <LDOM_XmlWriter.hxx>
51 #include <Precision.hxx>
52 #include <TColStd_ListIteratorOfListOfInteger.hxx>
53 #include <TColStd_ListIteratorOfListOfReal.hxx>
54 #include <TColStd_ListOfInteger.hxx>
55 #include <TColStd_ListOfReal.hxx>
56 #include <TColStd_SequenceOfHAsciiString.hxx>
57 #include <TCollection_HAsciiString.hxx>
58 #include <TopExp_Explorer.hxx>
60 #include <TopoDS_Shape.hxx>
62 using namespace SMESH;
63 using namespace SMESH::Controls;
69 GetPredicate( Predicate_ptr thePredicate )
71 return DownCast<Predicate_i*>(thePredicate);
81 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
83 SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
84 return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
89 toArray( const TColStd_ListOfInteger& aList )
91 SMESH::long_array_var anArray = new SMESH::long_array;
92 anArray->length( aList.Extent() );
93 TColStd_ListIteratorOfListOfInteger anIter( aList );
95 for( ; anIter.More(); anIter.Next() )
96 anArray[ i++ ] = anIter.Value();
98 return anArray._retn();
103 toArray( const TColStd_ListOfReal& aList )
105 SMESH::double_array_var anArray = new SMESH::double_array;
106 anArray->length( aList.Extent() );
107 TColStd_ListIteratorOfListOfReal anIter( aList );
109 for( ; anIter.More(); anIter.Next() )
110 anArray[ i++ ] = anIter.Value();
112 return anArray._retn();
115 static SMESH::Filter::Criterion createCriterion()
117 SMESH::Filter::Criterion aCriterion;
119 aCriterion.Type = FT_Undefined;
120 aCriterion.Compare = FT_Undefined;
121 aCriterion.Threshold = 0;
122 aCriterion.UnaryOp = FT_Undefined;
123 aCriterion.BinaryOp = FT_Undefined;
124 aCriterion.ThresholdStr = "";
125 aCriterion.ThresholdID = "";
126 aCriterion.Tolerance = Precision::Confusion();
127 aCriterion.TypeOfElement = SMESH::ALL;
128 aCriterion.Precision = -1;
133 static TopoDS_Shape getShapeByName( const char* theName )
137 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
138 SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
139 if ( !aStudy->_is_nil() )
141 SALOMEDS::Study::ListOfSObject_var aList = aStudy->FindObjectByName( theName, "GEOM" );
142 if ( aList->length() > 0 )
144 CORBA::Object_var anObj = aList[ 0 ]->GetObject();
145 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( anObj );
146 TopoDS_Shape shape = aSMESHGen->GeomObjectToShape( aGeomObj );
147 SALOME::UnRegister( aList ); // UnRegister() objects in aList
152 return TopoDS_Shape();
155 static TopoDS_Shape getShapeByID (const char* theID)
157 if ( theID && strlen( theID ) > 0 ) {
158 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
159 SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
160 if ( !aStudy->_is_nil() ) {
161 SALOMEDS::SObject_wrap aSObj = aStudy->FindObjectID(theID);
162 if ( !aSObj->_is_nil() ) {
163 CORBA::Object_var obj = aSObj->GetObject();
164 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
165 return aSMESHGen->GeomObjectToShape( aGeomObj );
169 return TopoDS_Shape();
172 static std::string getShapeNameByID (const char* theID)
174 if ( theID && strlen( theID ) > 0 ) {
175 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
176 SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
177 if ( !aStudy->_is_nil() ) {
178 SALOMEDS::SObject_wrap aSObj = aStudy->FindObjectID(theID);
179 if ( !aSObj->_is_nil() ) {
180 CORBA::String_var name = aSObj->GetName();
194 Description : An abstact class for all functors
196 Functor_i::Functor_i():
197 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
199 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
200 //PortableServer::ObjectId_var anObjectId =
201 // SMESH_Gen_i::GetPOA()->activate_object( this );
204 Functor_i::~Functor_i()
206 //TPythonDump()<<this<<".UnRegister()";
209 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
211 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
212 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
215 ElementType Functor_i::GetElementType()
217 return ( ElementType )myFunctorPtr->GetType();
222 Class : NumericalFunctor_i
223 Description : Base class for numerical functors
225 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
227 return myNumericalFunctorPtr->GetValue( theId );
230 SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals, CORBA::Boolean isLogarithmic)
232 std::vector<int> nbEvents;
233 std::vector<double> funValues;
234 std::vector<int> elements;
235 myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements,0,isLogarithmic);
237 SMESH::Histogram_var histogram = new SMESH::Histogram;
239 nbIntervals = CORBA::Short( Min( int( nbEvents.size()),
240 int( funValues.size() - 1 )));
241 if ( nbIntervals > 0 )
243 histogram->length( nbIntervals );
244 for ( int i = 0; i < nbIntervals; ++i )
246 HistogramRectangle& rect = histogram[i];
247 rect.nbEvents = nbEvents[i];
248 rect.min = funValues[i];
249 rect.max = funValues[i+1];
252 return histogram._retn();
255 SMESH::Histogram* NumericalFunctor_i::GetLocalHistogram(CORBA::Short nbIntervals,
256 CORBA::Boolean isLogarithmic,
257 SMESH::SMESH_IDSource_ptr object)
259 SMESH::Histogram_var histogram = new SMESH::Histogram;
261 std::vector<int> nbEvents;
262 std::vector<double> funValues;
263 std::vector<int> elements;
265 SMDS_ElemIteratorPtr elemIt;
266 if ( SMESH::DownCast< SMESH_GroupOnFilter_i* >( object ) ||
267 SMESH::DownCast< SMESH::Filter_i* >( object ))
269 elemIt = SMESH_Mesh_i::GetElements( object, GetElementType() );
270 if ( !elemIt ) return histogram._retn();
274 SMESH::SMESH_Mesh_var mesh = object->GetMesh();
275 SMESH::long_array_var objNbElems = object->GetNbElementsByType();
276 SMESH::long_array_var meshNbElems = mesh-> GetNbElementsByType();
277 if ( meshNbElems[ GetElementType() ] !=
278 objNbElems [ GetElementType() ] )
280 elements.reserve( objNbElems[ GetElementType() ]);
281 elemIt = SMESH_Mesh_i::GetElements( object, GetElementType() );
286 while ( elemIt->more() )
287 elements.push_back( elemIt->next()->GetID() );
288 if ( elements.empty() ) return histogram._retn();
291 myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements,0,isLogarithmic);
293 nbIntervals = CORBA::Short( Min( int( nbEvents.size()),
294 int( funValues.size() - 1 )));
295 if ( nbIntervals > 0 )
297 histogram->length( nbIntervals );
298 for ( int i = 0; i < nbIntervals; ++i )
300 HistogramRectangle& rect = histogram[i];
301 rect.nbEvents = nbEvents[i];
302 rect.min = funValues[i];
303 rect.max = funValues[i+1];
306 return histogram._retn();
309 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
311 myNumericalFunctorPtr->SetPrecision( thePrecision );
312 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
315 CORBA::Long NumericalFunctor_i::GetPrecision()
317 return myNumericalFunctorPtr->GetPrecision();
320 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
322 return myNumericalFunctorPtr;
327 Class : SMESH_MinimumAngle
328 Description : Functor for calculation of minimum angle
330 MinimumAngle_i::MinimumAngle_i()
332 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
333 myFunctorPtr = myNumericalFunctorPtr;
336 FunctorType MinimumAngle_i::GetFunctorType()
338 return SMESH::FT_MinimumAngle;
344 Description : Functor for calculating aspect ratio
346 AspectRatio_i::AspectRatio_i()
348 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
349 myFunctorPtr = myNumericalFunctorPtr;
352 FunctorType AspectRatio_i::GetFunctorType()
354 return SMESH::FT_AspectRatio;
359 Class : AspectRatio3D
360 Description : Functor for calculating aspect ratio 3D
362 AspectRatio3D_i::AspectRatio3D_i()
364 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
365 myFunctorPtr = myNumericalFunctorPtr;
368 FunctorType AspectRatio3D_i::GetFunctorType()
370 return SMESH::FT_AspectRatio3D;
376 Description : Functor for calculating warping
378 Warping_i::Warping_i()
380 myNumericalFunctorPtr.reset( new Controls::Warping() );
381 myFunctorPtr = myNumericalFunctorPtr;
384 FunctorType Warping_i::GetFunctorType()
386 return SMESH::FT_Warping;
392 Description : Functor for calculating taper
396 myNumericalFunctorPtr.reset( new Controls::Taper() );
397 myFunctorPtr = myNumericalFunctorPtr;
400 FunctorType Taper_i::GetFunctorType()
402 return SMESH::FT_Taper;
407 Description : Functor for calculating skew in degrees
411 myNumericalFunctorPtr.reset( new Controls::Skew() );
412 myFunctorPtr = myNumericalFunctorPtr;
415 FunctorType Skew_i::GetFunctorType()
417 return SMESH::FT_Skew;
422 Description : Functor for calculating area
426 myNumericalFunctorPtr.reset( new Controls::Area() );
427 myFunctorPtr = myNumericalFunctorPtr;
430 FunctorType Area_i::GetFunctorType()
432 return SMESH::FT_Area;
437 Description : Functor for calculating volume of 3D element
439 Volume3D_i::Volume3D_i()
441 myNumericalFunctorPtr.reset( new Controls::Volume() );
442 myFunctorPtr = myNumericalFunctorPtr;
445 FunctorType Volume3D_i::GetFunctorType()
447 return SMESH::FT_Volume3D;
451 Class : MaxElementLength2D_i
452 Description : Functor for calculating maximum length of 2D element
454 MaxElementLength2D_i::MaxElementLength2D_i()
456 myNumericalFunctorPtr.reset( new Controls::MaxElementLength2D() );
457 myFunctorPtr = myNumericalFunctorPtr;
460 FunctorType MaxElementLength2D_i::GetFunctorType()
462 return SMESH::FT_MaxElementLength2D;
466 Class : MaxElementLength3D_i
467 Description : Functor for calculating maximum length of 3D element
469 MaxElementLength3D_i::MaxElementLength3D_i()
471 myNumericalFunctorPtr.reset( new Controls::MaxElementLength3D() );
472 myFunctorPtr = myNumericalFunctorPtr;
475 FunctorType MaxElementLength3D_i::GetFunctorType()
477 return SMESH::FT_MaxElementLength3D;
482 Description : Functor for calculating length off edge
486 myNumericalFunctorPtr.reset( new Controls::Length() );
487 myFunctorPtr = myNumericalFunctorPtr;
490 FunctorType Length_i::GetFunctorType()
492 return SMESH::FT_Length;
497 Description : Functor for calculating length of edge
499 Length2D_i::Length2D_i()
501 myNumericalFunctorPtr.reset( new Controls::Length2D() );
502 myFunctorPtr = myNumericalFunctorPtr;
505 FunctorType Length2D_i::GetFunctorType()
507 return SMESH::FT_Length2D;
510 SMESH::Length2D::Values* Length2D_i::GetValues()
512 INFOS("Length2D_i::GetValues");
513 SMESH::Controls::Length2D::TValues aValues;
514 (dynamic_cast<SMESH::Controls::Length2D*>(myFunctorPtr.get()))->GetValues( aValues );
516 long i = 0, iEnd = aValues.size();
518 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
519 aResult->length(iEnd);
521 SMESH::Controls::Length2D::TValues::const_iterator anIter;
522 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
524 const SMESH::Controls::Length2D::Value& aVal = *anIter;
525 SMESH::Length2D::Value &aValue = aResult[ i ];
527 aValue.myLength = aVal.myLength;
528 aValue.myPnt1 = aVal.myPntId[ 0 ];
529 aValue.myPnt2 = aVal.myPntId[ 1 ];
532 INFOS("Length2D_i::GetValuess~");
533 return aResult._retn();
537 Class : MultiConnection_i
538 Description : Functor for calculating number of faces conneted to the edge
540 MultiConnection_i::MultiConnection_i()
542 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
543 myFunctorPtr = myNumericalFunctorPtr;
546 FunctorType MultiConnection_i::GetFunctorType()
548 return SMESH::FT_MultiConnection;
552 Class : BallDiameter_i
553 Description : Functor returning diameter of a ball element
555 BallDiameter_i::BallDiameter_i()
557 myNumericalFunctorPtr.reset( new Controls::BallDiameter() );
558 myFunctorPtr = myNumericalFunctorPtr;
561 FunctorType BallDiameter_i::GetFunctorType()
563 return SMESH::FT_BallDiameter;
567 Class : MultiConnection2D_i
568 Description : Functor for calculating number of faces conneted to the edge
570 MultiConnection2D_i::MultiConnection2D_i()
572 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
573 myFunctorPtr = myNumericalFunctorPtr;
576 FunctorType MultiConnection2D_i::GetFunctorType()
578 return SMESH::FT_MultiConnection2D;
581 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
583 INFOS("MultiConnection2D_i::GetValues");
584 SMESH::Controls::MultiConnection2D::MValues aValues;
585 (dynamic_cast<SMESH::Controls::MultiConnection2D*>(myFunctorPtr.get()))->GetValues( aValues );
587 long i = 0, iEnd = aValues.size();
589 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
590 aResult->length(iEnd);
592 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
593 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
595 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
596 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
598 aValue.myPnt1 = aVal.myPntId[ 0 ];
599 aValue.myPnt2 = aVal.myPntId[ 1 ];
600 aValue.myNbConnects = (*anIter).second;
603 INFOS("Multiconnection2D_i::GetValuess~");
604 return aResult._retn();
614 Description : Base class for all predicates
616 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
618 return myPredicatePtr->IsSatisfy( theId );
621 CORBA::Long Predicate_i::NbSatisfying( SMESH::SMESH_IDSource_ptr obj )
623 SMESH::SMESH_Mesh_var meshVar = obj->GetMesh();
624 const SMDS_Mesh* meshDS = MeshPtr2SMDSMesh( meshVar );
627 myPredicatePtr->SetMesh( meshDS );
629 SMDSAbs_ElementType elemType = SMDSAbs_ElementType( GetElementType() );
632 SMDS_ElemIteratorPtr elemIt =
633 SMESH::DownCast<SMESH_Mesh_i*>( meshVar )->GetElements( obj, GetElementType() );
635 while ( elemIt->more() )
637 const SMDS_MeshElement* e = elemIt->next();
638 if ( e && e->GetType() == elemType )
639 nb += myPredicatePtr->IsSatisfy( e->GetID() );
644 Controls::PredicatePtr Predicate_i::GetPredicate()
646 return myPredicatePtr;
650 Class : BadOrientedVolume_i
651 Description : Verify whether a mesh volume is incorrectly oriented from
652 the point of view of MED convention
654 BadOrientedVolume_i::BadOrientedVolume_i()
656 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
657 myFunctorPtr = myPredicatePtr = control;
660 FunctorType BadOrientedVolume_i::GetFunctorType()
662 return SMESH::FT_BadOrientedVolume;
666 Class : BareBorderVolume_i
667 Description : Verify whether a mesh volume has a free facet without a face on it
669 BareBorderVolume_i::BareBorderVolume_i()
671 Controls::PredicatePtr control( new Controls::BareBorderVolume() );
672 myFunctorPtr = myPredicatePtr = control;
675 FunctorType BareBorderVolume_i::GetFunctorType()
677 return SMESH::FT_BareBorderVolume;
681 Class : BareBorderFace_i
682 Description : Verify whether a mesh face has a free border without an edge on it
684 BareBorderFace_i::BareBorderFace_i()
686 Controls::PredicatePtr control( new Controls::BareBorderFace() );
687 myFunctorPtr = myPredicatePtr = control;
690 FunctorType BareBorderFace_i::GetFunctorType()
692 return SMESH::FT_BareBorderFace;
696 Class : OverConstrainedVolume_i
697 Description : Verify whether a mesh volume has only one facet shared with other volumes
699 OverConstrainedVolume_i::OverConstrainedVolume_i()
701 Controls::PredicatePtr control( new Controls::OverConstrainedVolume() );
702 myFunctorPtr = myPredicatePtr = control;
705 FunctorType OverConstrainedVolume_i::GetFunctorType()
707 return SMESH::FT_OverConstrainedVolume;
711 Class : OverConstrainedFace_i
712 Description : Verify whether a mesh face has only one border shared with other faces
714 OverConstrainedFace_i::OverConstrainedFace_i()
716 Controls::PredicatePtr control( new Controls::OverConstrainedFace() );
717 myFunctorPtr = myPredicatePtr = control;
720 FunctorType OverConstrainedFace_i::GetFunctorType()
722 return SMESH::FT_OverConstrainedFace;
726 Class : BelongToGeom_i
727 Description : Predicate for selection on geometrical support
729 BelongToGeom_i::BelongToGeom_i()
731 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
732 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
737 BelongToGeom_i::~BelongToGeom_i()
743 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
745 if ( theGeom->_is_nil() )
747 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
748 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
749 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
750 myBelongToGeomPtr->SetGeom( aLocShape );
751 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
754 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
756 myBelongToGeomPtr->SetGeom( theShape );
759 void BelongToGeom_i::SetElementType(ElementType theType)
761 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
762 TPythonDump()<<this<<".SetElementType("<<theType<<")";
765 FunctorType BelongToGeom_i::GetFunctorType()
767 return SMESH::FT_BelongToGeom;
770 void BelongToGeom_i::SetShapeName( const char* theName )
773 myShapeName = strdup( theName );
774 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
775 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
778 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
782 myShapeName = strdup( theName );
783 myShapeID = strdup( theID );
784 bool hasName = ( theName && theName[0] );
785 bool hasID = ( theID && theID[0] );
788 if ( hasName && hasID )
790 S = getShapeByID( myShapeID );
792 S = getShapeByName( myShapeName );
796 S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
798 myBelongToGeomPtr->SetGeom( S );
801 char* BelongToGeom_i::GetShapeName()
803 return CORBA::string_dup( myShapeName );
806 char* BelongToGeom_i::GetShapeID()
808 return CORBA::string_dup( myShapeID );
811 void BelongToGeom_i::SetTolerance( CORBA::Double theToler )
813 myBelongToGeomPtr->SetTolerance( theToler );
814 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
817 CORBA::Double BelongToGeom_i::GetTolerance()
819 return myBelongToGeomPtr->GetTolerance();
823 Class : BelongToSurface_i
824 Description : Predicate for selection on geometrical support
826 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
828 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
829 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
832 mySurfaceType = theSurfaceType;
835 BelongToSurface_i::~BelongToSurface_i()
841 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
843 if ( theGeom->_is_nil() )
845 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
846 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
847 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
849 if ( aLocShape.ShapeType() == TopAbs_FACE )
851 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
852 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
854 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
859 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
862 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
865 myShapeName = strdup( theName );
866 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
867 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
870 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
874 myShapeName = strdup( theName );
875 myShapeID = strdup( theID );
876 bool hasName = ( theName && theName[0] );
877 bool hasID = ( theID && theID[0] );
880 if ( hasName && hasID )
882 S = getShapeByID( myShapeID );
884 S = getShapeByName( myShapeName );
888 S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
890 myElementsOnSurfacePtr->SetSurface( S, (SMDSAbs_ElementType)theType );
893 char* BelongToSurface_i::GetShapeName()
895 return CORBA::string_dup( myShapeName );
898 char* BelongToSurface_i::GetShapeID()
900 return CORBA::string_dup( myShapeID );
903 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
905 myElementsOnSurfacePtr->SetTolerance( theToler );
906 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
909 CORBA::Double BelongToSurface_i::GetTolerance()
911 return myElementsOnSurfacePtr->GetTolerance();
914 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
916 myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
917 TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
920 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
922 return myElementsOnSurfacePtr->GetUseBoundaries();
927 Class : BelongToPlane_i
928 Description : Verify whether mesh element lie in pointed Geom planar object
931 BelongToPlane_i::BelongToPlane_i()
932 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
936 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
938 BelongToSurface_i::SetSurface( theGeom, theType );
939 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
942 FunctorType BelongToPlane_i::GetFunctorType()
944 return FT_BelongToPlane;
948 Class : BelongToCylinder_i
949 Description : Verify whether mesh element lie in pointed Geom planar object
952 BelongToCylinder_i::BelongToCylinder_i()
953 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
957 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
959 BelongToSurface_i::SetSurface( theGeom, theType );
960 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
963 FunctorType BelongToCylinder_i::GetFunctorType()
965 return FT_BelongToCylinder;
969 Class : BelongToGenSurface_i
970 Description : Verify whether mesh element lie in pointed Geom planar object
973 BelongToGenSurface_i::BelongToGenSurface_i()
974 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
978 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
980 if ( theGeom->_is_nil() )
982 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
983 if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
986 BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
987 TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
990 FunctorType BelongToGenSurface_i::GetFunctorType()
992 return FT_BelongToGenSurface;
996 Class : LyingOnGeom_i
997 Description : Predicate for selection on geometrical support
999 LyingOnGeom_i::LyingOnGeom_i()
1001 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1002 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1007 LyingOnGeom_i::~LyingOnGeom_i()
1013 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1015 if ( theGeom->_is_nil() )
1017 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1018 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1019 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1020 myLyingOnGeomPtr->SetGeom( aLocShape );
1021 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1024 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1026 myLyingOnGeomPtr->SetGeom( theShape );
1029 void LyingOnGeom_i::SetElementType(ElementType theType){
1030 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1031 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1034 FunctorType LyingOnGeom_i::GetFunctorType()
1036 return SMESH::FT_LyingOnGeom;
1039 void LyingOnGeom_i::SetShapeName( const char* theName )
1042 myShapeName = strdup( theName );
1043 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1044 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1047 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1051 myShapeName = strdup( theName );
1052 myShapeID = strdup( theID );
1053 bool hasName = ( theName && theName[0] );
1054 bool hasID = ( theID && theID[0] );
1057 if ( hasName && hasID )
1059 S = getShapeByID( myShapeID );
1061 S = getShapeByName( myShapeName );
1065 S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
1067 myLyingOnGeomPtr->SetGeom( S );
1070 char* LyingOnGeom_i::GetShapeName()
1072 return CORBA::string_dup( myShapeName );
1075 char* LyingOnGeom_i::GetShapeID()
1077 return CORBA::string_dup( myShapeID );
1080 void LyingOnGeom_i::SetTolerance( CORBA::Double theToler )
1082 myLyingOnGeomPtr->SetTolerance( theToler );
1083 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1086 CORBA::Double LyingOnGeom_i::GetTolerance()
1088 return myLyingOnGeomPtr->GetTolerance();
1092 Class : FreeBorders_i
1093 Description : Predicate for free borders
1095 FreeBorders_i::FreeBorders_i()
1097 myPredicatePtr.reset(new Controls::FreeBorders());
1098 myFunctorPtr = myPredicatePtr;
1101 FunctorType FreeBorders_i::GetFunctorType()
1103 return SMESH::FT_FreeBorders;
1108 Description : Predicate for free borders
1110 FreeEdges_i::FreeEdges_i()
1111 : myFreeEdgesPtr( new Controls::FreeEdges() )
1113 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1116 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1118 INFOS("FreeEdges_i::GetBorders");
1119 SMESH::Controls::FreeEdges::TBorders aBorders;
1120 myFreeEdgesPtr->GetBoreders( aBorders );
1122 long i = 0, iEnd = aBorders.size();
1124 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1125 aResult->length(iEnd);
1127 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1128 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1130 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1131 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1133 aBorder.myElemId = aBord.myElemId;
1134 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1135 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1138 INFOS("FreeEdges_i::GetBorders~");
1139 return aResult._retn();
1142 FunctorType FreeEdges_i::GetFunctorType()
1144 return SMESH::FT_FreeEdges;
1149 Description : Predicate for free faces
1151 FreeFaces_i::FreeFaces_i()
1153 myPredicatePtr.reset(new Controls::FreeFaces());
1154 myFunctorPtr = myPredicatePtr;
1157 FunctorType FreeFaces_i::GetFunctorType()
1159 return SMESH::FT_FreeFaces;
1164 Description : Predicate for free nodes
1166 FreeNodes_i::FreeNodes_i()
1168 myPredicatePtr.reset(new Controls::FreeNodes());
1169 myFunctorPtr = myPredicatePtr;
1172 FunctorType FreeNodes_i::GetFunctorType()
1174 return SMESH::FT_FreeNodes;
1178 Class : EqualNodes_i
1179 Description : Predicate for Equal nodes
1181 EqualNodes_i::EqualNodes_i()
1183 myCoincidentNodesPtr.reset(new Controls::CoincidentNodes());
1184 myFunctorPtr = myPredicatePtr = myCoincidentNodesPtr;
1187 FunctorType EqualNodes_i::GetFunctorType()
1189 return SMESH::FT_EqualNodes;
1192 void EqualNodes_i::SetTolerance( double tol )
1194 myCoincidentNodesPtr->SetTolerance( tol );
1197 double EqualNodes_i::GetTolerance()
1199 return myCoincidentNodesPtr->GetTolerance();
1203 Class : EqualEdges_i
1204 Description : Predicate for Equal Edges
1206 EqualEdges_i::EqualEdges_i()
1208 myPredicatePtr.reset(new Controls::CoincidentElements1D());
1209 myFunctorPtr = myPredicatePtr;
1212 FunctorType EqualEdges_i::GetFunctorType()
1214 return SMESH::FT_EqualEdges;
1218 Class : EqualFaces_i
1219 Description : Predicate for Equal Faces
1221 EqualFaces_i::EqualFaces_i()
1223 myPredicatePtr.reset(new Controls::CoincidentElements2D());
1224 myFunctorPtr = myPredicatePtr;
1227 FunctorType EqualFaces_i::GetFunctorType()
1229 return SMESH::FT_EqualFaces;
1233 Class : EqualVolumes_i
1234 Description : Predicate for Equal Volumes
1236 EqualVolumes_i::EqualVolumes_i()
1238 myPredicatePtr.reset(new Controls::CoincidentElements3D());
1239 myFunctorPtr = myPredicatePtr;
1242 FunctorType EqualVolumes_i::GetFunctorType()
1244 return SMESH::FT_EqualVolumes;
1249 Class : RangeOfIds_i
1250 Description : Predicate for Range of Ids.
1251 Range may be specified with two ways.
1252 1. Using AddToRange method
1253 2. With SetRangeStr method. Parameter of this method is a string
1254 like as "1,2,3,50-60,63,67,70-"
1257 RangeOfIds_i::RangeOfIds_i()
1259 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1260 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1263 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1265 CORBA::Long iEnd = theIds.length();
1266 for ( CORBA::Long i = 0; i < iEnd; i++ )
1267 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1268 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1271 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1273 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1274 return myRangeOfIdsPtr->SetRangeStr(
1275 TCollection_AsciiString( (Standard_CString)theRange ) );
1278 char* RangeOfIds_i::GetRangeStr()
1280 TCollection_AsciiString aStr;
1281 myRangeOfIdsPtr->GetRangeStr( aStr );
1282 return CORBA::string_dup( aStr.ToCString() );
1285 void RangeOfIds_i::SetElementType( ElementType theType )
1287 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1288 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1291 FunctorType RangeOfIds_i::GetFunctorType()
1293 return SMESH::FT_RangeOfIds;
1297 Class : LinearOrQuadratic_i
1298 Description : Predicate to verify whether a mesh element is linear
1300 LinearOrQuadratic_i::LinearOrQuadratic_i()
1302 myLinearOrQuadraticPtr.reset(new Controls::LinearOrQuadratic());
1303 myFunctorPtr = myPredicatePtr = myLinearOrQuadraticPtr;
1306 void LinearOrQuadratic_i::SetElementType(ElementType theType)
1308 myLinearOrQuadraticPtr->SetType(SMDSAbs_ElementType(theType));
1309 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1312 FunctorType LinearOrQuadratic_i::GetFunctorType()
1314 return SMESH::FT_LinearOrQuadratic;
1318 Class : GroupColor_i
1319 Description : Functor for check color of group to whic mesh element belongs to
1321 GroupColor_i::GroupColor_i()
1323 myGroupColorPtr.reset(new Controls::GroupColor());
1324 myFunctorPtr = myPredicatePtr = myGroupColorPtr;
1327 FunctorType GroupColor_i::GetFunctorType()
1329 return SMESH::FT_GroupColor;
1332 void GroupColor_i::SetColorStr( const char* theColor )
1334 myGroupColorPtr->SetColorStr(
1335 TCollection_AsciiString( (Standard_CString)theColor ) );
1336 TPythonDump()<<this<<".SetColorStr('"<<theColor<<"')";
1339 char* GroupColor_i::GetColorStr()
1341 TCollection_AsciiString aStr;
1342 myGroupColorPtr->GetColorStr( aStr );
1343 return CORBA::string_dup( aStr.ToCString() );
1346 void GroupColor_i::SetElementType(ElementType theType)
1348 myGroupColorPtr->SetType(SMDSAbs_ElementType(theType));
1349 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1353 Class : ElemGeomType_i
1354 Description : Predicate check is element has indicated geometry type
1356 ElemGeomType_i::ElemGeomType_i()
1358 myElemGeomTypePtr.reset(new Controls::ElemGeomType());
1359 myFunctorPtr = myPredicatePtr = myElemGeomTypePtr;
1362 void ElemGeomType_i::SetElementType(ElementType theType)
1364 myElemGeomTypePtr->SetType(SMDSAbs_ElementType(theType));
1365 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1368 void ElemGeomType_i::SetGeometryType(GeometryType theType)
1370 myElemGeomTypePtr->SetGeomType(SMDSAbs_GeometryType(theType));
1371 TPythonDump()<<this<<".SetGeometryType("<<theType<<")";
1374 GeometryType ElemGeomType_i::GetGeometryType() const
1376 return (GeometryType)myElemGeomTypePtr->GetGeomType();
1379 FunctorType ElemGeomType_i::GetFunctorType()
1381 return SMESH::FT_ElemGeomType;
1385 Class : ElemEntityType_i
1386 Description : Predicate check is element has indicated entity type
1388 ElemEntityType_i::ElemEntityType_i()
1390 myElemEntityTypePtr.reset(new Controls::ElemEntityType());
1391 myFunctorPtr = myPredicatePtr = myElemEntityTypePtr;
1394 void ElemEntityType_i::SetElementType(ElementType theType)
1396 myElemEntityTypePtr->SetType(SMDSAbs_ElementType(theType));
1397 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1400 void ElemEntityType_i::SetEntityType(EntityType theEntityType)
1402 myElemEntityTypePtr->SetElemEntityType(SMDSAbs_EntityType (theEntityType));
1403 TPythonDump()<<this<<".SetEntityType("<<theEntityType<<")";
1405 EntityType ElemEntityType_i::GetEntityType() const
1407 return (EntityType) myElemEntityTypePtr->GetElemEntityType();
1410 FunctorType ElemEntityType_i::GetFunctorType()
1412 return SMESH::FT_EntityType;
1416 Class : CoplanarFaces_i
1417 Description : Returns true if a mesh face is a coplanar neighbour to a given one
1419 CoplanarFaces_i::CoplanarFaces_i()
1421 myCoplanarFacesPtr.reset(new Controls::CoplanarFaces());
1422 myFunctorPtr = myPredicatePtr = myCoplanarFacesPtr;
1425 void CoplanarFaces_i::SetFace ( CORBA::Long theFaceID )
1427 myCoplanarFacesPtr->SetFace(theFaceID);
1428 TPythonDump()<<this<<".SetFace("<<theFaceID<<")";
1431 void CoplanarFaces_i::SetTolerance( CORBA::Double theToler )
1433 myCoplanarFacesPtr->SetTolerance(theToler);
1434 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1437 CORBA::Long CoplanarFaces_i::GetFace () const
1439 return myCoplanarFacesPtr->GetFace();
1442 char* CoplanarFaces_i::GetFaceAsString () const
1444 TCollection_AsciiString str(Standard_Integer(myCoplanarFacesPtr->GetFace()));
1445 return CORBA::string_dup( str.ToCString() );
1448 CORBA::Double CoplanarFaces_i::GetTolerance() const
1450 return myCoplanarFacesPtr->GetTolerance();
1453 FunctorType CoplanarFaces_i::GetFunctorType()
1455 return SMESH::FT_CoplanarFaces;
1459 * Class : ConnectedElements_i
1460 * Description : Returns true if an element is connected via other elements to the element
1461 * located at a given point.
1463 ConnectedElements_i::ConnectedElements_i()
1465 myConnectedElementsPtr.reset(new Controls::ConnectedElements());
1466 myFunctorPtr = myPredicatePtr = myConnectedElementsPtr;
1469 FunctorType ConnectedElements_i::GetFunctorType()
1471 return FT_ConnectedElements;
1474 void ConnectedElements_i::SetElementType( ElementType theType )
1476 myConnectedElementsPtr->SetType( SMDSAbs_ElementType( theType ));
1477 TPythonDump() << this << ".SetElementType( " << theType << " )";
1480 void ConnectedElements_i::SetPoint( CORBA::Double x, CORBA::Double y, CORBA::Double z )
1482 myConnectedElementsPtr->SetPoint( x,y,z );
1484 TPythonDump() << this << ".SetPoint( " << x << ", " << y << ", " << z << " )";
1487 void ConnectedElements_i::SetVertex( GEOM::GEOM_Object_ptr vertex )
1488 throw (SALOME::SALOME_Exception)
1490 TopoDS_Shape shape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( vertex );
1491 if ( shape.IsNull() )
1492 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetVertex(): NULL Vertex",
1493 SALOME::BAD_PARAM );
1495 TopExp_Explorer v( shape, TopAbs_VERTEX );
1497 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetVertex(): empty vertex",
1498 SALOME::BAD_PARAM );
1500 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( v.Current() ));
1501 myConnectedElementsPtr->SetPoint( p.X(), p.Y(), p.Z() );
1503 CORBA::String_var id = vertex->GetStudyEntry();
1504 myVertexID = id.in();
1506 TPythonDump() << this << ".SetVertex( " << vertex << " )";
1509 void ConnectedElements_i::SetNode ( CORBA::Long nodeID )
1510 throw (SALOME::SALOME_Exception)
1513 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetNode(): nodeID must be > 0",
1514 SALOME::BAD_PARAM );
1516 myConnectedElementsPtr->SetNode( nodeID );
1518 TPythonDump() << this << ".SetNode( " << nodeID << " )";
1522 * \brief This is a comfort method for Filter dialog
1524 void ConnectedElements_i::SetThreshold ( const char* threshold,
1525 SMESH::ConnectedElements::ThresholdType type )
1526 throw (SALOME::SALOME_Exception)
1529 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetThreshold(): NULL threshold",
1530 SALOME::BAD_PARAM );
1533 case SMESH::ConnectedElements::POINT: // read 3 node coordinates ///////////////////
1535 vector< double > xyz;
1540 while ( *threshold &&
1541 *threshold != '+' &&
1542 *threshold != '-' &&
1543 !isdigit( *threshold ))
1547 // read a coordinate
1548 xyz.push_back( strtod( threshold, &endptr ));
1549 if ( threshold == endptr )
1551 xyz.resize( xyz.size() - 1 );
1556 while ( xyz.size() < 3 );
1558 if ( xyz.size() < 3 )
1559 THROW_SALOME_CORBA_EXCEPTION
1560 ( "ConnectedElements_i::SetThreshold(): invalid point coordinates", SALOME::BAD_PARAM );
1562 SetPoint( xyz[0], xyz[1], xyz[2] );
1565 case SMESH::ConnectedElements::VERTEX: // get a VERTEX by its entry /////////////////
1567 SALOMEDS::Study_var study = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
1568 if ( study->_is_nil() )
1569 THROW_SALOME_CORBA_EXCEPTION
1570 ( "ConnectedElements_i::SetThreshold(): NULL current study", SALOME::BAD_PARAM );
1571 SALOMEDS::SObject_wrap sobj = study->FindObjectID( threshold );
1572 if ( sobj->_is_nil() )
1573 THROW_SALOME_CORBA_EXCEPTION
1574 ( "ConnectedElements_i::SetThreshold(): invalid vertex study entry", SALOME::BAD_PARAM );
1575 CORBA::Object_var obj = sobj->GetObject();
1576 GEOM::GEOM_Object_var vertex = GEOM::GEOM_Object::_narrow( obj );
1577 if ( vertex->_is_nil() )
1578 THROW_SALOME_CORBA_EXCEPTION
1579 ( "ConnectedElements_i::SetThreshold(): no GEOM_Object in SObject", SALOME::BAD_PARAM );
1580 SetVertex( vertex );
1583 case SMESH::ConnectedElements::NODE: // read a node ID ////////////////////////////
1586 int id = strtol( threshold, &endptr, 10 );
1587 if ( threshold == endptr )
1588 THROW_SALOME_CORBA_EXCEPTION
1589 ( "ConnectedElements_i::SetThreshold(): invalid node ID", SALOME::BAD_PARAM );
1594 THROW_SALOME_CORBA_EXCEPTION
1595 ( "ConnectedElements_i::SetThreshold(): invalid ThresholdType", SALOME::BAD_PARAM );
1599 char* ConnectedElements_i::GetThreshold ( SMESH::ConnectedElements::ThresholdType& type )
1601 std::string threshold;
1602 if ( !myVertexID.empty() )
1604 threshold = myVertexID;
1605 type = SMESH::ConnectedElements::VERTEX;
1609 std::vector<double> xyz = myConnectedElementsPtr->GetPoint();
1610 if ( xyz.size() == 3 )
1612 threshold = SMESH_Comment( xyz[0] ) << "; " << xyz[1] << "; " << xyz[2];
1613 type = SMESH::ConnectedElements::POINT;
1617 threshold = SMESH_Comment( myConnectedElementsPtr->GetNode() );
1618 type = SMESH::ConnectedElements::NODE;
1621 return CORBA::string_dup( threshold.c_str() );
1625 Class : Comparator_i
1626 Description : Base class for comparators
1628 Comparator_i::Comparator_i():
1629 myNumericalFunctor( NULL )
1632 Comparator_i::~Comparator_i()
1634 if ( myNumericalFunctor )
1635 myNumericalFunctor->UnRegister();
1638 void Comparator_i::SetMargin( CORBA::Double theValue )
1640 myComparatorPtr->SetMargin( theValue );
1641 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1644 CORBA::Double Comparator_i::GetMargin()
1646 return myComparatorPtr->GetMargin();
1649 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1651 if ( myNumericalFunctor )
1652 myNumericalFunctor->UnRegister();
1654 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1656 if ( myNumericalFunctor )
1658 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1659 myNumericalFunctor->Register();
1660 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1664 Controls::ComparatorPtr Comparator_i::GetComparator()
1666 return myComparatorPtr;
1669 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1671 return myNumericalFunctor;
1677 Description : Comparator "<"
1679 LessThan_i::LessThan_i()
1681 myComparatorPtr.reset( new Controls::LessThan() );
1682 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1685 FunctorType LessThan_i::GetFunctorType()
1687 return SMESH::FT_LessThan;
1693 Description : Comparator ">"
1695 MoreThan_i::MoreThan_i()
1697 myComparatorPtr.reset( new Controls::MoreThan() );
1698 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1701 FunctorType MoreThan_i::GetFunctorType()
1703 return SMESH::FT_MoreThan;
1709 Description : Comparator "="
1711 EqualTo_i::EqualTo_i()
1712 : myEqualToPtr( new Controls::EqualTo() )
1714 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1717 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1719 myEqualToPtr->SetTolerance( theToler );
1720 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1723 CORBA::Double EqualTo_i::GetTolerance()
1725 return myEqualToPtr->GetTolerance();
1728 FunctorType EqualTo_i::GetFunctorType()
1730 return SMESH::FT_EqualTo;
1734 Class : LogicalNOT_i
1735 Description : Logical NOT predicate
1737 LogicalNOT_i::LogicalNOT_i()
1738 : myPredicate( NULL ),
1739 myLogicalNOTPtr( new Controls::LogicalNOT() )
1741 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1744 LogicalNOT_i::~LogicalNOT_i()
1747 myPredicate->UnRegister();
1750 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1753 myPredicate->UnRegister();
1755 myPredicate = SMESH::GetPredicate(thePredicate);
1758 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1759 myPredicate->Register();
1760 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1764 FunctorType LogicalNOT_i::GetFunctorType()
1766 return SMESH::FT_LogicalNOT;
1769 Predicate_i* LogicalNOT_i::GetPredicate_i()
1776 Class : LogicalBinary_i
1777 Description : Base class for binary logical predicate
1779 LogicalBinary_i::LogicalBinary_i()
1780 : myPredicate1( NULL ),
1781 myPredicate2( NULL )
1784 LogicalBinary_i::~LogicalBinary_i()
1787 myPredicate1->UnRegister();
1790 myPredicate2->UnRegister();
1793 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1796 myPredicate1->SetMesh( theMesh );
1799 myPredicate2->SetMesh( theMesh );
1802 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1805 myPredicate1->UnRegister();
1807 myPredicate1 = SMESH::GetPredicate(thePredicate);
1809 if ( myPredicate1 ){
1810 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1811 myPredicate1->Register();
1812 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1816 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1819 myPredicate2->UnRegister();
1821 myPredicate2 = SMESH::GetPredicate(thePredicate);
1823 if ( myPredicate2 ){
1824 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1825 myPredicate2->Register();
1826 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1830 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1832 return myLogicalBinaryPtr;
1835 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1837 return myPredicate1;
1839 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1841 return myPredicate2;
1846 Class : LogicalAND_i
1847 Description : Logical AND
1849 LogicalAND_i::LogicalAND_i()
1851 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1852 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1855 FunctorType LogicalAND_i::GetFunctorType()
1857 return SMESH::FT_LogicalAND;
1863 Description : Logical OR
1865 LogicalOR_i::LogicalOR_i()
1867 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1868 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1871 FunctorType LogicalOR_i::GetFunctorType()
1873 return SMESH::FT_LogicalOR;
1881 FilterManager_i::FilterManager_i()
1882 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1884 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
1885 //PortableServer::ObjectId_var anObjectId =
1886 // SMESH_Gen_i::GetPOA()->activate_object( this );
1890 FilterManager_i::~FilterManager_i()
1892 //TPythonDump()<<this<<".UnRegister()";
1896 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1898 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1899 SMESH::MinimumAngle_var anObj = aServant->_this();
1900 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1901 return anObj._retn();
1905 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1907 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1908 SMESH::AspectRatio_var anObj = aServant->_this();
1909 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1910 return anObj._retn();
1914 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1916 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1917 SMESH::AspectRatio3D_var anObj = aServant->_this();
1918 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1919 return anObj._retn();
1923 Warping_ptr FilterManager_i::CreateWarping()
1925 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1926 SMESH::Warping_var anObj = aServant->_this();
1927 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1928 return anObj._retn();
1932 Taper_ptr FilterManager_i::CreateTaper()
1934 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1935 SMESH::Taper_var anObj = aServant->_this();
1936 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1937 return anObj._retn();
1941 Skew_ptr FilterManager_i::CreateSkew()
1943 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1944 SMESH::Skew_var anObj = aServant->_this();
1945 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1946 return anObj._retn();
1950 Area_ptr FilterManager_i::CreateArea()
1952 SMESH::Area_i* aServant = new SMESH::Area_i();
1953 SMESH::Area_var anObj = aServant->_this();
1954 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1955 return anObj._retn();
1959 Volume3D_ptr FilterManager_i::CreateVolume3D()
1961 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
1962 SMESH::Volume3D_var anObj = aServant->_this();
1963 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
1964 return anObj._retn();
1968 MaxElementLength2D_ptr FilterManager_i::CreateMaxElementLength2D()
1970 SMESH::MaxElementLength2D_i* aServant = new SMESH::MaxElementLength2D_i();
1971 SMESH::MaxElementLength2D_var anObj = aServant->_this();
1972 TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength2D()";
1973 return anObj._retn();
1977 MaxElementLength3D_ptr FilterManager_i::CreateMaxElementLength3D()
1979 SMESH::MaxElementLength3D_i* aServant = new SMESH::MaxElementLength3D_i();
1980 SMESH::MaxElementLength3D_var anObj = aServant->_this();
1981 TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength3D()";
1982 return anObj._retn();
1986 Length_ptr FilterManager_i::CreateLength()
1988 SMESH::Length_i* aServant = new SMESH::Length_i();
1989 SMESH::Length_var anObj = aServant->_this();
1990 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1991 return anObj._retn();
1994 Length2D_ptr FilterManager_i::CreateLength2D()
1996 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1997 SMESH::Length2D_var anObj = aServant->_this();
1998 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1999 return anObj._retn();
2002 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
2004 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
2005 SMESH::MultiConnection_var anObj = aServant->_this();
2006 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
2007 return anObj._retn();
2010 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
2012 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
2013 SMESH::MultiConnection2D_var anObj = aServant->_this();
2014 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
2015 return anObj._retn();
2018 BallDiameter_ptr FilterManager_i::CreateBallDiameter()
2020 SMESH::BallDiameter_i* aServant = new SMESH::BallDiameter_i();
2021 SMESH::BallDiameter_var anObj = aServant->_this();
2022 TPythonDump()<<aServant<<" = "<<this<<".CreateBallDiameter()";
2023 return anObj._retn();
2026 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
2028 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
2029 SMESH::BelongToGeom_var anObj = aServant->_this();
2030 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
2031 return anObj._retn();
2034 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
2036 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
2037 SMESH::BelongToPlane_var anObj = aServant->_this();
2038 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
2039 return anObj._retn();
2042 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
2044 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
2045 SMESH::BelongToCylinder_var anObj = aServant->_this();
2046 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
2047 return anObj._retn();
2050 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
2052 SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
2053 SMESH::BelongToGenSurface_var anObj = aServant->_this();
2054 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
2055 return anObj._retn();
2058 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
2060 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
2061 SMESH::LyingOnGeom_var anObj = aServant->_this();
2062 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
2063 return anObj._retn();
2066 CoplanarFaces_ptr FilterManager_i::CreateCoplanarFaces()
2068 SMESH::CoplanarFaces_i* aServant = new SMESH::CoplanarFaces_i();
2069 SMESH::CoplanarFaces_var anObj = aServant->_this();
2070 TPythonDump()<<aServant<<" = "<<this<<".CreateCoplanarFaces()";
2071 return anObj._retn();
2074 ConnectedElements_ptr FilterManager_i::CreateConnectedElements()
2076 SMESH::ConnectedElements_i* aServant = new SMESH::ConnectedElements_i();
2077 SMESH::ConnectedElements_var anObj = aServant->_this();
2078 TPythonDump()<<aServant<<" = "<<this<<".CreateConnectedElements()";
2079 return anObj._retn();
2082 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
2084 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
2085 SMESH::FreeBorders_var anObj = aServant->_this();
2086 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
2087 return anObj._retn();
2090 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
2092 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
2093 SMESH::FreeEdges_var anObj = aServant->_this();
2094 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
2095 return anObj._retn();
2098 FreeFaces_ptr FilterManager_i::CreateFreeFaces()
2100 SMESH::FreeFaces_i* aServant = new SMESH::FreeFaces_i();
2101 SMESH::FreeFaces_var anObj = aServant->_this();
2102 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeFaces()";
2103 return anObj._retn();
2106 FreeNodes_ptr FilterManager_i::CreateFreeNodes()
2108 SMESH::FreeNodes_i* aServant = new SMESH::FreeNodes_i();
2109 SMESH::FreeNodes_var anObj = aServant->_this();
2110 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeNodes()";
2111 return anObj._retn();
2114 EqualNodes_ptr FilterManager_i::CreateEqualNodes()
2116 SMESH::EqualNodes_i* aServant = new SMESH::EqualNodes_i();
2117 SMESH::EqualNodes_var anObj = aServant->_this();
2118 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualNodes()";
2119 return anObj._retn();
2122 EqualEdges_ptr FilterManager_i::CreateEqualEdges()
2124 SMESH::EqualEdges_i* aServant = new SMESH::EqualEdges_i();
2125 SMESH::EqualEdges_var anObj = aServant->_this();
2126 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualEdges()";
2127 return anObj._retn();
2129 EqualFaces_ptr FilterManager_i::CreateEqualFaces()
2131 SMESH::EqualFaces_i* aServant = new SMESH::EqualFaces_i();
2132 SMESH::EqualFaces_var anObj = aServant->_this();
2133 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualFaces()";
2134 return anObj._retn();
2136 EqualVolumes_ptr FilterManager_i::CreateEqualVolumes()
2138 SMESH::EqualVolumes_i* aServant = new SMESH::EqualVolumes_i();
2139 SMESH::EqualVolumes_var anObj = aServant->_this();
2140 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualVolumes()";
2141 return anObj._retn();
2144 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
2146 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
2147 SMESH::RangeOfIds_var anObj = aServant->_this();
2148 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
2149 return anObj._retn();
2152 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
2154 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
2155 SMESH::BadOrientedVolume_var anObj = aServant->_this();
2156 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
2157 return anObj._retn();
2160 BareBorderVolume_ptr FilterManager_i::CreateBareBorderVolume()
2162 SMESH::BareBorderVolume_i* aServant = new SMESH::BareBorderVolume_i();
2163 SMESH::BareBorderVolume_var anObj = aServant->_this();
2164 TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderVolume()";
2165 return anObj._retn();
2168 BareBorderFace_ptr FilterManager_i::CreateBareBorderFace()
2170 SMESH::BareBorderFace_i* aServant = new SMESH::BareBorderFace_i();
2171 SMESH::BareBorderFace_var anObj = aServant->_this();
2172 TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderFace()";
2173 return anObj._retn();
2176 OverConstrainedVolume_ptr FilterManager_i::CreateOverConstrainedVolume()
2178 SMESH::OverConstrainedVolume_i* aServant = new SMESH::OverConstrainedVolume_i();
2179 SMESH::OverConstrainedVolume_var anObj = aServant->_this();
2180 TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedVolume()";
2181 return anObj._retn();
2184 OverConstrainedFace_ptr FilterManager_i::CreateOverConstrainedFace()
2186 SMESH::OverConstrainedFace_i* aServant = new SMESH::OverConstrainedFace_i();
2187 SMESH::OverConstrainedFace_var anObj = aServant->_this();
2188 TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedFace()";
2189 return anObj._retn();
2192 LessThan_ptr FilterManager_i::CreateLessThan()
2194 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
2195 SMESH::LessThan_var anObj = aServant->_this();
2196 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
2197 return anObj._retn();
2200 MoreThan_ptr FilterManager_i::CreateMoreThan()
2202 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
2203 SMESH::MoreThan_var anObj = aServant->_this();
2204 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
2205 return anObj._retn();
2208 EqualTo_ptr FilterManager_i::CreateEqualTo()
2210 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
2211 SMESH::EqualTo_var anObj = aServant->_this();
2212 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
2213 return anObj._retn();
2216 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
2218 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
2219 SMESH::LogicalNOT_var anObj = aServant->_this();
2220 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
2221 return anObj._retn();
2224 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
2226 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
2227 SMESH::LogicalAND_var anObj = aServant->_this();
2228 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
2229 return anObj._retn();
2232 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
2234 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
2235 SMESH::LogicalOR_var anObj = aServant->_this();
2236 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
2237 return anObj._retn();
2240 LinearOrQuadratic_ptr FilterManager_i::CreateLinearOrQuadratic()
2242 SMESH::LinearOrQuadratic_i* aServant = new SMESH::LinearOrQuadratic_i();
2243 SMESH::LinearOrQuadratic_var anObj = aServant->_this();
2244 TPythonDump()<<aServant<<" = "<<this<<".CreateLinearOrQuadratic()";
2245 return anObj._retn();
2248 GroupColor_ptr FilterManager_i::CreateGroupColor()
2250 SMESH::GroupColor_i* aServant = new SMESH::GroupColor_i();
2251 SMESH::GroupColor_var anObj = aServant->_this();
2252 TPythonDump()<<aServant<<" = "<<this<<".CreateGroupColor()";
2253 return anObj._retn();
2256 ElemGeomType_ptr FilterManager_i::CreateElemGeomType()
2258 SMESH::ElemGeomType_i* aServant = new SMESH::ElemGeomType_i();
2259 SMESH::ElemGeomType_var anObj = aServant->_this();
2260 TPythonDump()<<aServant<<" = "<<this<<".CreateElemGeomType()";
2261 return anObj._retn();
2264 ElemEntityType_ptr FilterManager_i::CreateElemEntityType()
2266 SMESH::ElemEntityType_i* aServant = new SMESH::ElemEntityType_i();
2267 SMESH::ElemEntityType_var anObj = aServant->_this();
2268 TPythonDump()<<aServant<<" = "<<this<<".CreateElemEntityType()";
2269 return anObj._retn();
2272 Filter_ptr FilterManager_i::CreateFilter()
2274 SMESH::Filter_i* aServant = new SMESH::Filter_i();
2275 SMESH::Filter_var anObj = aServant->_this();
2276 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
2277 return anObj._retn();
2280 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
2282 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
2283 SMESH::FilterLibrary_var anObj = aServant->_this();
2284 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary('"<<aFileName<<"')";
2285 return anObj._retn();
2288 FilterLibrary_ptr FilterManager_i::CreateLibrary()
2290 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
2291 SMESH::FilterLibrary_var anObj = aServant->_this();
2292 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
2293 return anObj._retn();
2296 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
2298 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
2299 return remove( aFileName ) ? false : true;
2302 //=============================================================================
2304 * SMESH_Gen_i::CreateFilterManager
2306 * Create filter manager
2308 //=============================================================================
2310 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
2312 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2313 SMESH::FilterManager_var anObj = aFilter->_this();
2314 return anObj._retn();
2322 //=======================================================================
2323 // name : Filter_i::Filter_i
2324 // Purpose : Constructor
2325 //=======================================================================
2326 Filter_i::Filter_i()
2327 : myPredicate( NULL )
2330 //=======================================================================
2331 // name : Filter_i::~Filter_i
2332 // Purpose : Destructor
2333 //=======================================================================
2334 Filter_i::~Filter_i()
2337 myPredicate->UnRegister();
2339 if(!CORBA::is_nil(myMesh))
2340 myMesh->UnRegister();
2342 //TPythonDump()<<this<<".UnRegister()";
2345 //=======================================================================
2346 // name : Filter_i::SetPredicate
2347 // Purpose : Set predicate
2348 //=======================================================================
2349 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
2352 myPredicate->UnRegister();
2354 myPredicate = SMESH::GetPredicate(thePredicate);
2358 myFilter.SetPredicate( myPredicate->GetPredicate() );
2359 myPredicate->Register();
2360 if ( const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh))
2361 myPredicate->GetPredicate()->SetMesh( aMesh );
2362 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
2364 std::list<TPredicateChangeWaiter*>::iterator i = myWaiters.begin();
2365 for ( ; i != myWaiters.end(); ++i )
2366 (*i)->PredicateChanged();
2369 //=======================================================================
2370 // name : Filter_i::GetElementType
2371 // Purpose : Get entity type
2372 //=======================================================================
2373 SMESH::ElementType Filter_i::GetElementType()
2375 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
2378 //=======================================================================
2379 // name : Filter_i::SetMesh
2380 // Purpose : Set mesh
2381 //=======================================================================
2384 SetMesh( SMESH_Mesh_ptr theMesh )
2386 if(!CORBA::is_nil(theMesh))
2387 theMesh->Register();
2389 if(!CORBA::is_nil(myMesh))
2390 myMesh->UnRegister();
2392 myMesh = SMESH_Mesh::_duplicate( theMesh );
2393 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
2396 if ( const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2397 myPredicate->GetPredicate()->SetMesh( aMesh );
2404 return GetElementsId(myMesh);
2407 //=======================================================================
2408 // name : Filter_i::GetElementsId
2409 // Purpose : Get ids of entities
2410 //=======================================================================
2413 GetElementsId( Predicate_i* thePredicate,
2414 const SMDS_Mesh* theMesh,
2415 Controls::Filter::TIdSequence& theSequence )
2418 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
2423 GetElementsId( Predicate_i* thePredicate,
2424 SMESH_Mesh_ptr theMesh,
2425 Controls::Filter::TIdSequence& theSequence )
2428 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2429 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
2434 GetElementsId( SMESH_Mesh_ptr theMesh )
2436 SMESH::long_array_var anArray = new SMESH::long_array;
2437 if(!CORBA::is_nil(theMesh) && myPredicate){
2439 Controls::Filter::TIdSequence aSequence;
2440 GetElementsId(myPredicate,theMesh,aSequence);
2441 long i = 0, iEnd = aSequence.size();
2442 anArray->length( iEnd );
2443 for ( ; i < iEnd; i++ )
2444 anArray[ i ] = aSequence[i];
2446 return anArray._retn();
2449 //=============================================================================
2451 * \brief Returns number of mesh elements per each \a EntityType
2453 //=============================================================================
2455 SMESH::long_array* ::Filter_i::GetMeshInfo()
2457 SMESH::long_array_var aRes = new SMESH::long_array();
2458 aRes->length(SMESH::Entity_Last);
2459 for (int i = 0; i < SMESH::Entity_Last; i++)
2462 if ( !CORBA::is_nil(myMesh) && myPredicate )
2464 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2465 SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2466 while ( it->more() )
2468 const SMDS_MeshElement* anElem = it->next();
2469 if ( myPredicate->IsSatisfy( anElem->GetID() ) )
2470 aRes[ anElem->GetEntityType() ]++;
2474 return aRes._retn();
2477 //=============================================================================
2479 * \brief Returns number of mesh elements of each \a ElementType
2481 //=============================================================================
2483 SMESH::long_array* ::Filter_i::GetNbElementsByType()
2485 SMESH::long_array_var aRes = new SMESH::long_array();
2486 aRes->length(SMESH::NB_ELEMENT_TYPES);
2487 for (int i = 0; i < SMESH::NB_ELEMENT_TYPES; i++)
2490 if ( !CORBA::is_nil(myMesh) && myPredicate ) {
2491 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2492 SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2493 CORBA::Long& nbElems = aRes[ GetElementType() ];
2494 while ( it->more() )
2496 const SMDS_MeshElement* anElem = it->next();
2497 if ( myPredicate->IsSatisfy( anElem->GetID() ) )
2502 return aRes._retn();
2506 //================================================================================
2508 * \brief Return GetElementType() within an array
2509 * Implement SMESH_IDSource interface
2511 //================================================================================
2513 SMESH::array_of_ElementType* Filter_i::GetTypes()
2515 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
2517 // check if any element passes through the filter
2518 if ( !CORBA::is_nil(myMesh) && myPredicate )
2520 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2521 SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2522 bool satisfies = false;
2523 while ( !satisfies && it->more() )
2524 satisfies = myPredicate->IsSatisfy( it->next()->GetID() );
2527 types[0] = GetElementType();
2530 return types._retn();
2533 //=======================================================================
2534 //function : GetMesh
2535 //purpose : Returns mesh
2536 //=======================================================================
2538 SMESH::SMESH_Mesh_ptr Filter_i::GetMesh()
2540 return SMESH_Mesh::_duplicate( myMesh );
2543 //=======================================================================
2544 //function : GetVtkUgStream
2545 //purpose : Return data vtk unstructured grid (not implemented)
2546 //=======================================================================
2548 SALOMEDS::TMPFile* Filter_i::GetVtkUgStream()
2550 SALOMEDS::TMPFile_var SeqFile;
2551 return SeqFile._retn();
2554 //================================================================================
2556 * \brief Stores an object to be notified on change of predicate
2558 //================================================================================
2560 void Filter_i::AddWaiter( TPredicateChangeWaiter* waiter )
2563 myWaiters.push_back( waiter );
2566 //================================================================================
2568 * \brief Removes an object to be notified on change of predicate
2570 //================================================================================
2572 void Filter_i::RemoveWaiter( TPredicateChangeWaiter* waiter )
2574 myWaiters.remove( waiter );
2577 //=======================================================================
2578 // name : getCriteria
2579 // Purpose : Retrieve criterions from predicate
2580 //=======================================================================
2581 static inline bool getCriteria( Predicate_i* thePred,
2582 SMESH::Filter::Criteria_out theCriteria )
2584 int aFType = thePred->GetFunctorType();
2590 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2591 getCriteria( aPred, theCriteria );
2592 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2599 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2600 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2601 if ( !getCriteria( aPred1, theCriteria ) )
2603 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2604 return getCriteria( aPred2, theCriteria );
2610 // resize theCriteria
2611 CORBA::ULong i = theCriteria->length();
2612 theCriteria->length( i + 1 );
2613 theCriteria[ i ] = createCriterion();
2615 // set members of the added Criterion
2617 theCriteria[ i ].Type = aFType;
2618 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
2622 case FT_FreeBorders:
2625 case FT_LinearOrQuadratic:
2629 case FT_EqualVolumes:
2630 case FT_BadOrientedVolume:
2631 case FT_BareBorderVolume:
2632 case FT_BareBorderFace:
2633 case FT_OverConstrainedVolume:
2634 case FT_OverConstrainedFace:
2638 case FT_BelongToGeom:
2640 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
2641 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2642 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2643 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2646 case FT_BelongToPlane:
2647 case FT_BelongToCylinder:
2648 case FT_BelongToGenSurface:
2650 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
2651 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2652 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2653 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2656 case FT_LyingOnGeom:
2658 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
2659 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2660 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2661 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2664 case FT_CoplanarFaces:
2666 CoplanarFaces_i* aPred = dynamic_cast<CoplanarFaces_i*>( thePred );
2667 theCriteria[ i ].ThresholdID = aPred->GetFaceAsString();
2668 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2671 case FT_ConnectedElements:
2673 ConnectedElements_i* aPred = dynamic_cast<ConnectedElements_i*>( thePred );
2674 SMESH::ConnectedElements::ThresholdType type;
2675 CORBA::String_var threshold = aPred->GetThreshold( type );
2677 case SMESH::ConnectedElements::POINT:
2678 theCriteria[ i ].ThresholdStr = threshold; break;
2679 case SMESH::ConnectedElements::VERTEX:
2680 theCriteria[ i ].ThresholdID = threshold; break;
2681 case SMESH::ConnectedElements::NODE:
2682 theCriteria[ i ].Threshold = atof( threshold.in() ); break;
2689 EqualNodes_i* aPred = dynamic_cast<EqualNodes_i*>( thePred );
2690 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2695 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
2696 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
2703 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
2704 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
2705 theCriteria[ i ].Compare = aFType;
2706 theCriteria[ i ].Threshold = aCompar->GetMargin();
2707 if ( aFType == FT_EqualTo )
2709 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
2710 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
2716 GroupColor_i* aPred = dynamic_cast<GroupColor_i*>( thePred );
2717 theCriteria[ i ].ThresholdStr = aPred->GetColorStr();
2720 case FT_ElemGeomType:
2722 ElemGeomType_i* aPred = dynamic_cast<ElemGeomType_i*>( thePred );
2723 theCriteria[ i ].Threshold = (double)aPred->GetGeometryType();
2728 ElemEntityType_i* aPred = dynamic_cast<ElemEntityType_i*>( thePred );
2729 theCriteria[ i ].Threshold = (double)aPred->GetEntityType();
2737 //=======================================================================
2738 // name : Filter_i::GetCriteria
2739 // Purpose : Retrieve criterions from predicate
2740 //=======================================================================
2741 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2743 theCriteria = new SMESH::Filter::Criteria;
2744 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2747 //=======================================================================
2748 // name : Filter_i::SetCriteria
2749 // Purpose : Create new predicate and set criterions in it
2750 //=======================================================================
2751 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2753 SetPredicate( SMESH::Predicate::_nil() );
2755 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2756 FilterManager_ptr aFilterMgr = aFilter->_this();
2758 // CREATE two lists ( PREDICATES and LOG OP )
2761 TPythonDump()<<"aCriteria = []";
2762 std::list<SMESH::Predicate_ptr> aPredicates;
2763 std::list<int> aBinaries;
2764 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2766 int aCriterion = theCriteria[ i ].Type;
2767 int aCompare = theCriteria[ i ].Compare;
2768 double aThreshold = theCriteria[ i ].Threshold;
2769 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2770 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2771 int aUnary = theCriteria[ i ].UnaryOp;
2772 int aBinary = theCriteria[ i ].BinaryOp;
2773 double aTolerance = theCriteria[ i ].Tolerance;
2774 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
2775 long aPrecision = theCriteria[ i ].Precision;
2779 pd << "aCriterion = SMESH.Filter.Criterion("
2780 << aCriterion << ", "
2782 << aThreshold << ", '"
2783 << aThresholdStr << "', '"
2784 << aThresholdID << "', "
2787 << aTolerance << ", "
2788 << aTypeOfElem << ", "
2789 << aPrecision << ")";
2793 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2794 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2796 switch ( aCriterion )
2800 case SMESH::FT_MultiConnection:
2801 aFunctor = aFilterMgr->CreateMultiConnection();
2803 case SMESH::FT_MultiConnection2D:
2804 aFunctor = aFilterMgr->CreateMultiConnection2D();
2806 case SMESH::FT_Length:
2807 aFunctor = aFilterMgr->CreateLength();
2809 case SMESH::FT_Length2D:
2810 aFunctor = aFilterMgr->CreateLength2D();
2812 case SMESH::FT_AspectRatio:
2813 aFunctor = aFilterMgr->CreateAspectRatio();
2815 case SMESH::FT_AspectRatio3D:
2816 aFunctor = aFilterMgr->CreateAspectRatio3D();
2818 case SMESH::FT_Warping:
2819 aFunctor = aFilterMgr->CreateWarping();
2821 case SMESH::FT_MinimumAngle:
2822 aFunctor = aFilterMgr->CreateMinimumAngle();
2824 case SMESH::FT_Taper:
2825 aFunctor = aFilterMgr->CreateTaper();
2827 case SMESH::FT_Skew:
2828 aFunctor = aFilterMgr->CreateSkew();
2830 case SMESH::FT_Area:
2831 aFunctor = aFilterMgr->CreateArea();
2833 case SMESH::FT_Volume3D:
2834 aFunctor = aFilterMgr->CreateVolume3D();
2836 case SMESH::FT_MaxElementLength2D:
2837 aFunctor = aFilterMgr->CreateMaxElementLength2D();
2839 case SMESH::FT_MaxElementLength3D:
2840 aFunctor = aFilterMgr->CreateMaxElementLength3D();
2842 case SMESH::FT_BallDiameter:
2843 aFunctor = aFilterMgr->CreateBallDiameter();
2848 case SMESH::FT_FreeBorders:
2849 aPredicate = aFilterMgr->CreateFreeBorders();
2851 case SMESH::FT_FreeEdges:
2852 aPredicate = aFilterMgr->CreateFreeEdges();
2854 case SMESH::FT_FreeFaces:
2855 aPredicate = aFilterMgr->CreateFreeFaces();
2857 case SMESH::FT_FreeNodes:
2858 aPredicate = aFilterMgr->CreateFreeNodes();
2860 case SMESH::FT_EqualNodes:
2862 SMESH::EqualNodes_ptr pred = aFilterMgr->CreateEqualNodes();
2863 pred->SetTolerance( aTolerance );
2867 case SMESH::FT_EqualEdges:
2868 aPredicate = aFilterMgr->CreateEqualEdges();
2870 case SMESH::FT_EqualFaces:
2871 aPredicate = aFilterMgr->CreateEqualFaces();
2873 case SMESH::FT_EqualVolumes:
2874 aPredicate = aFilterMgr->CreateEqualVolumes();
2876 case SMESH::FT_BelongToGeom:
2878 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2879 tmpPred->SetElementType( aTypeOfElem );
2880 tmpPred->SetShape( aThresholdID, aThresholdStr );
2881 tmpPred->SetTolerance( aTolerance );
2882 aPredicate = tmpPred;
2885 case SMESH::FT_BelongToPlane:
2886 case SMESH::FT_BelongToCylinder:
2887 case SMESH::FT_BelongToGenSurface:
2889 SMESH::BelongToSurface_ptr tmpPred;
2890 switch ( aCriterion ) {
2891 case SMESH::FT_BelongToPlane:
2892 tmpPred = aFilterMgr->CreateBelongToPlane(); break;
2893 case SMESH::FT_BelongToCylinder:
2894 tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
2896 tmpPred = aFilterMgr->CreateBelongToGenSurface();
2898 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2899 tmpPred->SetTolerance( aTolerance );
2900 aPredicate = tmpPred;
2903 case SMESH::FT_LyingOnGeom:
2905 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2906 tmpPred->SetElementType( aTypeOfElem );
2907 tmpPred->SetShape( aThresholdID, aThresholdStr );
2908 tmpPred->SetTolerance( aTolerance );
2909 aPredicate = tmpPred;
2912 case SMESH::FT_RangeOfIds:
2914 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2915 tmpPred->SetRangeStr( aThresholdStr );
2916 tmpPred->SetElementType( aTypeOfElem );
2917 aPredicate = tmpPred;
2920 case SMESH::FT_BadOrientedVolume:
2922 aPredicate = aFilterMgr->CreateBadOrientedVolume();
2925 case SMESH::FT_BareBorderVolume:
2927 aPredicate = aFilterMgr->CreateBareBorderVolume();
2930 case SMESH::FT_BareBorderFace:
2932 aPredicate = aFilterMgr->CreateBareBorderFace();
2935 case SMESH::FT_OverConstrainedVolume:
2937 aPredicate = aFilterMgr->CreateOverConstrainedVolume();
2940 case SMESH::FT_OverConstrainedFace:
2942 aPredicate = aFilterMgr->CreateOverConstrainedFace();
2945 case SMESH::FT_LinearOrQuadratic:
2947 SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
2948 tmpPred->SetElementType( aTypeOfElem );
2949 aPredicate = tmpPred;
2952 case SMESH::FT_GroupColor:
2954 SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor();
2955 tmpPred->SetElementType( aTypeOfElem );
2956 tmpPred->SetColorStr( aThresholdStr );
2957 aPredicate = tmpPred;
2960 case SMESH::FT_ElemGeomType:
2962 SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType();
2963 tmpPred->SetElementType( aTypeOfElem );
2964 tmpPred->SetGeometryType( (GeometryType)(int)(aThreshold + 0.5) );
2965 aPredicate = tmpPred;
2968 case SMESH::FT_EntityType:
2970 SMESH::ElemEntityType_ptr tmpPred = aFilterMgr->CreateElemEntityType();
2971 tmpPred->SetElementType( aTypeOfElem );
2972 tmpPred->SetEntityType( EntityType( (int (aThreshold + 0.5))));
2973 aPredicate = tmpPred;
2976 case SMESH::FT_CoplanarFaces:
2978 SMESH::CoplanarFaces_ptr tmpPred = aFilterMgr->CreateCoplanarFaces();
2979 tmpPred->SetFace( atol (aThresholdID ));
2980 tmpPred->SetTolerance( aTolerance );
2981 aPredicate = tmpPred;
2984 case SMESH::FT_ConnectedElements:
2986 SMESH::ConnectedElements_ptr tmpPred = aFilterMgr->CreateConnectedElements();
2987 if ( strlen( aThresholdID ) > 0 ) // shape ID
2988 tmpPred->SetThreshold( aThresholdID, SMESH::ConnectedElements::VERTEX );
2989 else if ( strlen( aThresholdStr ) > 0 ) // point coords
2990 tmpPred->SetThreshold( aThresholdStr, SMESH::ConnectedElements::POINT );
2991 else if ( aThreshold >= 1 )
2992 tmpPred->SetNode( (CORBA::Long) aThreshold ); // node ID
2993 tmpPred->SetElementType( aTypeOfElem );
2994 aPredicate = tmpPred;
3003 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
3005 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
3007 if ( aCompare == SMESH::FT_LessThan )
3008 aComparator = aFilterMgr->CreateLessThan();
3009 else if ( aCompare == SMESH::FT_MoreThan )
3010 aComparator = aFilterMgr->CreateMoreThan();
3011 else if ( aCompare == SMESH::FT_EqualTo )
3012 aComparator = aFilterMgr->CreateEqualTo();
3016 aComparator->SetNumFunctor( aFunctor );
3017 aComparator->SetMargin( aThreshold );
3019 if ( aCompare == FT_EqualTo )
3021 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
3022 anEqualTo->SetTolerance( aTolerance );
3025 aPredicate = aComparator;
3027 aFunctor->SetPrecision( aPrecision );
3031 if ( aUnary == FT_LogicalNOT )
3033 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
3034 aNotPred->SetPredicate( aPredicate );
3035 aPredicate = aNotPred;
3039 aPredicates.push_back( aPredicate );
3040 aBinaries.push_back( aBinary );
3041 pd <<"aCriteria.append(aCriterion)";
3044 TPythonDump pd; pd<<this<<".SetCriteria(aCriteria)";
3046 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
3048 // combine all "AND" operations
3050 std::list<SMESH::Predicate_ptr> aResList;
3052 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
3053 std::list<int>::iterator aBinaryIter;
3055 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
3056 int aPrevBinary = SMESH::FT_Undefined;
3057 if ( !aBinaries.empty() )
3058 aBinaries.back() = SMESH::FT_Undefined;
3060 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
3061 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
3062 ++aPredIter, ++aBinaryIter )
3064 int aCurrBinary = *aBinaryIter;
3066 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
3068 if ( aPrevBinary == SMESH::FT_LogicalAND )
3071 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
3072 aBinaryPred->SetPredicate1( aPrevPredicate );
3073 aBinaryPred->SetPredicate2( *aPredIter );
3074 aCurrPred = aBinaryPred;
3077 aCurrPred = *aPredIter;
3079 if ( aCurrBinary != SMESH::FT_LogicalAND )
3080 aResList.push_back( aCurrPred );
3082 aPrevPredicate = aCurrPred;
3083 aPrevBinary = aCurrBinary;
3086 // combine all "OR" operations
3088 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
3090 if ( aResList.size() == 1 )
3091 aResPredicate = *aResList.begin();
3092 else if ( aResList.size() > 1 )
3094 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
3095 aResPredicate = *anIter;
3097 for ( ; anIter != aResList.end(); ++anIter )
3099 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
3100 aBinaryPred->SetPredicate1( aResPredicate );
3101 aBinaryPred->SetPredicate2( *anIter );
3102 aResPredicate = aBinaryPred;
3106 SetPredicate( aResPredicate );
3107 if ( !aResPredicate->_is_nil() )
3108 aResPredicate->UnRegister();
3110 return !aResPredicate->_is_nil();
3113 //=======================================================================
3114 // name : Filter_i::GetPredicate_i
3115 // Purpose : Get implementation of predicate
3116 //=======================================================================
3117 Predicate_i* Filter_i::GetPredicate_i()
3122 //=======================================================================
3123 // name : Filter_i::GetPredicate
3124 // Purpose : Get predicate
3125 //=======================================================================
3126 Predicate_ptr Filter_i::GetPredicate()
3128 if ( myPredicate == 0 )
3129 return SMESH::Predicate::_nil();
3132 SMESH::Predicate_var anObj = myPredicate->_this();
3133 // if ( SMESH::Functor_i* fun = SMESH::DownCast<SMESH::Functor_i*>( anObj ))
3134 // TPythonDump() << fun << " = " << this << ".GetPredicate()";
3135 return anObj._retn();
3143 #define ATTR_TYPE "type"
3144 #define ATTR_COMPARE "compare"
3145 #define ATTR_THRESHOLD "threshold"
3146 #define ATTR_UNARY "unary"
3147 #define ATTR_BINARY "binary"
3148 #define ATTR_THRESHOLD_STR "threshold_str"
3149 #define ATTR_TOLERANCE "tolerance"
3150 #define ATTR_ELEMENT_TYPE "ElementType"
3152 //=======================================================================
3154 // Purpose : Convert bool to LDOMString
3155 //=======================================================================
3156 static inline LDOMString toString( CORBA::Boolean val )
3158 return val ? "logical not" : "";
3161 //=======================================================================
3163 // Purpose : Convert LDOMString to bool
3164 //=======================================================================
3165 static inline bool toBool( const LDOMString& theStr )
3167 return theStr.equals( "logical not" );
3170 //=======================================================================
3172 // Purpose : Convert double to LDOMString
3173 //=======================================================================
3174 static inline LDOMString toString( CORBA::Double val )
3177 sprintf( a, "%e", val );
3178 return LDOMString( a );
3181 //=======================================================================
3183 // Purpose : Convert LDOMString to double
3184 //=======================================================================
3185 static inline double toDouble( const LDOMString& theStr )
3187 return atof( theStr.GetString() );
3190 //=======================================================================
3192 // Purpose : Convert functor type to LDOMString
3193 //=======================================================================
3194 static inline LDOMString toString( CORBA::Long theType )
3198 case FT_AspectRatio : return "Aspect ratio";
3199 case FT_Warping : return "Warping";
3200 case FT_MinimumAngle : return "Minimum angle";
3201 case FT_Taper : return "Taper";
3202 case FT_Skew : return "Skew";
3203 case FT_Area : return "Area";
3204 case FT_Volume3D : return "Volume3D";
3205 case FT_MaxElementLength2D: return "Max element length 2D";
3206 case FT_MaxElementLength3D: return "Max element length 3D";
3207 case FT_BelongToGeom : return "Belong to Geom";
3208 case FT_BelongToPlane : return "Belong to Plane";
3209 case FT_BelongToCylinder: return "Belong to Cylinder";
3210 case FT_BelongToGenSurface: return "Belong to Generic Surface";
3211 case FT_LyingOnGeom : return "Lying on Geom";
3212 case FT_BadOrientedVolume:return "Bad Oriented Volume";
3213 case FT_BareBorderVolume: return "Volumes with bare border";
3214 case FT_BareBorderFace : return "Faces with bare border";
3215 case FT_OverConstrainedVolume: return "Over-constrained Volumes";
3216 case FT_OverConstrainedFace : return "Over-constrained Faces";
3217 case FT_RangeOfIds : return "Range of IDs";
3218 case FT_FreeBorders : return "Free borders";
3219 case FT_FreeEdges : return "Free edges";
3220 case FT_FreeFaces : return "Free faces";
3221 case FT_FreeNodes : return "Free nodes";
3222 case FT_EqualNodes : return "Equal nodes";
3223 case FT_EqualEdges : return "Equal edges";
3224 case FT_EqualFaces : return "Equal faces";
3225 case FT_EqualVolumes : return "Equal volumes";
3226 case FT_MultiConnection : return "Borders at multi-connections";
3227 case FT_MultiConnection2D:return "Borders at multi-connections 2D";
3228 case FT_Length : return "Length";
3229 case FT_Length2D : return "Length 2D";
3230 case FT_LessThan : return "Less than";
3231 case FT_MoreThan : return "More than";
3232 case FT_EqualTo : return "Equal to";
3233 case FT_LogicalNOT : return "Not";
3234 case FT_LogicalAND : return "And";
3235 case FT_LogicalOR : return "Or";
3236 case FT_GroupColor : return "Color of Group";
3237 case FT_LinearOrQuadratic : return "Linear or Quadratic";
3238 case FT_ElemGeomType : return "Element geomtry type";
3239 case FT_EntityType : return "Entity type";
3240 case FT_Undefined : return "";
3241 default : return "";
3245 //=======================================================================
3246 // name : toFunctorType
3247 // Purpose : Convert LDOMString to functor type
3248 //=======================================================================
3249 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
3251 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
3252 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
3253 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
3254 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
3255 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
3256 else if ( theStr.equals( "Area" ) ) return FT_Area;
3257 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
3258 else if ( theStr.equals( "Max element length 2D" ) ) return FT_MaxElementLength2D;
3259 else if ( theStr.equals( "Max element length 3D" ) ) return FT_MaxElementLength3D;
3260 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
3261 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
3262 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
3263 else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface;
3264 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
3265 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
3266 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
3267 else if ( theStr.equals( "Free faces" ) ) return FT_FreeFaces;
3268 else if ( theStr.equals( "Free nodes" ) ) return FT_FreeNodes;
3269 else if ( theStr.equals( "Equal nodes" ) ) return FT_EqualNodes;
3270 else if ( theStr.equals( "Equal edges" ) ) return FT_EqualEdges;
3271 else if ( theStr.equals( "Equal faces" ) ) return FT_EqualFaces;
3272 else if ( theStr.equals( "Equal volumes" ) ) return FT_EqualVolumes;
3273 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
3274 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
3275 else if ( theStr.equals( "Length" ) ) return FT_Length;
3276 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
3277 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
3278 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
3279 else if ( theStr.equals( "Volumes with bare border" ) ) return FT_BareBorderVolume;
3280 else if ( theStr.equals( "Faces with bare border" ) ) return FT_BareBorderFace;
3281 else if ( theStr.equals( "Over-constrained Volumes" ) ) return FT_OverConstrainedVolume;
3282 else if ( theStr.equals( "Over-constrained Faces" ) ) return FT_OverConstrainedFace;
3283 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
3284 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
3285 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
3286 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
3287 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
3288 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
3289 else if ( theStr.equals( "Color of Group" ) ) return FT_GroupColor;
3290 else if ( theStr.equals( "Linear or Quadratic" ) ) return FT_LinearOrQuadratic;
3291 else if ( theStr.equals( "Element geomtry type" ) ) return FT_ElemGeomType;
3292 else if ( theStr.equals( "Entity type" ) ) return FT_EntityType;
3293 else if ( theStr.equals( "" ) ) return FT_Undefined;
3294 else return FT_Undefined;
3297 //=======================================================================
3298 // name : toFunctorType
3299 // Purpose : Convert LDOMString to value of ElementType enumeration
3300 //=======================================================================
3301 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
3303 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
3304 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
3305 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
3306 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
3307 else return SMESH::ALL;
3310 //=======================================================================
3312 // Purpose : Convert ElementType to string
3313 //=======================================================================
3314 static inline LDOMString toString( const SMESH::ElementType theType )
3318 case SMESH::NODE : return "NODE";
3319 case SMESH::EDGE : return "EDGE";
3320 case SMESH::FACE : return "FACE";
3321 case SMESH::VOLUME : return "VOLUME";
3322 case SMESH::ALL : return "ALL";
3323 default : return "";
3327 //=======================================================================
3328 // name : findFilter
3329 // Purpose : Find filter in document
3330 //=======================================================================
3331 static LDOM_Element findFilter( const char* theFilterName,
3332 const LDOM_Document& theDoc,
3333 LDOM_Node* theParent = 0 )
3335 LDOM_Element aRootElement = theDoc.getDocumentElement();
3336 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
3337 return LDOM_Element();
3339 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
3340 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
3342 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
3343 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3345 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
3346 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
3347 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
3349 if ( theParent != 0 )
3350 *theParent = aTypeNode;
3351 return (LDOM_Element&)aFilter;
3355 return LDOM_Element();
3358 //=======================================================================
3359 // name : getSectionName
3360 // Purpose : Get name of section of filters
3361 //=======================================================================
3362 static const char* getSectionName( const ElementType theType )
3366 case SMESH::NODE : return "Filters for nodes";
3367 case SMESH::EDGE : return "Filters for edges";
3368 case SMESH::FACE : return "Filters for faces";
3369 case SMESH::VOLUME : return "Filters for volumes";
3370 case SMESH::ALL : return "Filters for elements";
3371 default : return "";
3375 //=======================================================================
3376 // name : getSection
3377 // Purpose : Create section for filters corresponding to the entity type
3378 //=======================================================================
3379 static LDOM_Node getSection( const ElementType theType,
3380 LDOM_Document& theDoc,
3381 const bool toCreate = false )
3383 LDOM_Element aRootElement = theDoc.getDocumentElement();
3384 if ( aRootElement.isNull() )
3388 bool anExist = false;
3389 const char* aSectionName = getSectionName( theType );
3390 if ( strcmp( aSectionName, "" ) == 0 )
3393 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
3395 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
3397 aNode = aSections.item( i );
3398 LDOM_Element& anItem = ( LDOM_Element& )aNode;
3399 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
3406 // Create new section if necessary
3411 LDOM_Element aNewItem = theDoc.createElement( "section" );
3412 aNewItem.setAttribute( "name", aSectionName );
3413 aRootElement.appendChild( aNewItem );
3423 //=======================================================================
3424 // name : createFilterItem
3425 // Purpose : Create filter item or LDOM document
3426 //=======================================================================
3427 static LDOM_Element createFilterItem( const char* theName,
3428 SMESH::Filter_ptr theFilter,
3429 LDOM_Document& theDoc )
3431 // create new filter in document
3432 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
3433 aFilterItem.setAttribute( "name", theName );
3435 // save filter criterions
3436 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3438 if ( !theFilter->GetCriteria( aCriteria ) )
3439 return LDOM_Element();
3441 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
3443 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
3445 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
3446 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
3447 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
3448 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
3449 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
3451 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
3452 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
3453 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
3454 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
3456 aFilterItem.appendChild( aCriterionItem );
3462 //=======================================================================
3463 // name : FilterLibrary_i::FilterLibrary_i
3464 // Purpose : Constructor
3465 //=======================================================================
3466 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
3468 myFileName = strdup( theFileName );
3469 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
3470 myFilterMgr = aFilterMgr->_this();
3474 // Try to use existing library file
3475 bool anExists = false;
3476 if ( !aParser.parse( myFileName ) )
3478 myDoc = aParser.getDocument();
3481 // Create a new XML document if it doesn't exist
3483 myDoc = LDOM_Document::createDocument( LDOMString() );
3485 LDOM_Element aRootElement = myDoc.getDocumentElement();
3486 if ( aRootElement.isNull() )
3488 // If the existing document is empty --> try to create a new one
3490 myDoc = LDOM_Document::createDocument( LDOMString() );
3494 //=======================================================================
3495 // name : FilterLibrary_i::FilterLibrary_i
3496 // Purpose : Constructor
3497 //=======================================================================
3498 FilterLibrary_i::FilterLibrary_i()
3501 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
3502 myFilterMgr = aFilter->_this();
3504 myDoc = LDOM_Document::createDocument( LDOMString() );
3507 FilterLibrary_i::~FilterLibrary_i()
3510 //TPythonDump()<<this<<".UnRegister()";
3513 //=======================================================================
3514 // name : FilterLibrary_i::Copy
3515 // Purpose : Create filter and initialize it with values from library
3516 //=======================================================================
3517 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
3519 Filter_ptr aRes = Filter::_nil();
3520 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
3522 if ( aFilter.isNull() )
3525 std::list<SMESH::Filter::Criterion> aCriteria;
3527 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
3528 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
3530 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
3532 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
3533 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
3534 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
3535 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
3536 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
3538 SMESH::Filter::Criterion aCriterion = createCriterion();
3540 aCriterion.Type = toFunctorType( aTypeStr );
3541 aCriterion.Compare = toFunctorType( aCompareStr );
3542 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
3543 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
3545 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
3547 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
3549 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3550 ? val : atof( str.GetString() );
3552 str = aCrit->getAttribute( ATTR_TOLERANCE );
3553 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3554 ? val : atof( str.GetString() );
3556 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
3557 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
3560 sprintf( a, "%d", val );
3561 aCriterion.ThresholdStr = strdup( a );
3564 aCriterion.ThresholdStr = str.GetString();
3566 aCriteria.push_back( aCriterion );
3569 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
3570 aCriteriaVar->length( aCriteria.size() );
3573 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
3575 for( ; anIter != aCriteria.end(); ++anIter )
3576 aCriteriaVar[ i++ ] = *anIter;
3578 aRes = myFilterMgr->CreateFilter();
3579 aRes->SetCriteria( aCriteriaVar.inout() );
3581 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
3586 //=======================================================================
3587 // name : FilterLibrary_i::SetFileName
3588 // Purpose : Set file name for library
3589 //=======================================================================
3590 void FilterLibrary_i::SetFileName( const char* theFileName )
3593 myFileName = strdup( theFileName );
3594 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
3597 //=======================================================================
3598 // name : FilterLibrary_i::GetFileName
3599 // Purpose : Get file name of library
3600 //=======================================================================
3601 char* FilterLibrary_i::GetFileName()
3603 return CORBA::string_dup( myFileName );
3606 //=======================================================================
3607 // name : FilterLibrary_i::Add
3608 // Purpose : Add new filter to library
3609 //=======================================================================
3610 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
3612 // if filter already in library or entry filter is null do nothing
3613 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3614 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
3617 // get section corresponding to the filter type
3618 ElementType anEntType = theFilter->GetElementType();
3620 LDOM_Node aSection = getSection( anEntType, myDoc, true );
3621 if ( aSection.isNull() )
3624 // create filter item
3625 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
3626 if ( aFilterItem.isNull() )
3630 aSection.appendChild( aFilterItem );
3631 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3632 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
3637 //=======================================================================
3638 // name : FilterLibrary_i::Add
3639 // Purpose : Add new filter to library
3640 //=======================================================================
3641 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
3643 // if filter already in library or entry filter is null do nothing
3644 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3645 if ( !aFilterNode.isNull() )
3648 LDOM_Node aSection = getSection( theType, myDoc, true );
3649 if ( aSection.isNull() )
3652 // create filter item
3653 Filter_var aFilter = myFilterMgr->CreateFilter();
3655 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
3656 if ( aFilterItem.isNull() )
3660 aSection.appendChild( aFilterItem );
3661 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
3666 //=======================================================================
3667 // name : FilterLibrary_i::Delete
3668 // Purpose : Delete filter from library
3669 //=======================================================================
3670 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
3672 LDOM_Node aParentNode;
3673 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
3674 if ( aFilterNode.isNull() || aParentNode.isNull() )
3677 aParentNode.removeChild( aFilterNode );
3678 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
3682 //=======================================================================
3683 // name : FilterLibrary_i::Replace
3684 // Purpose : Replace existing filter with entry filter.
3685 // IMPORTANT : If filter does not exist it is not created
3686 //=======================================================================
3687 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
3688 const char* theNewName,
3689 Filter_ptr theFilter )
3691 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
3692 if ( aFilterItem.isNull() || theFilter->_is_nil() )
3695 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
3696 if ( aNewItem.isNull() )
3700 aFilterItem.ReplaceElement( aNewItem );
3701 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3702 TPythonDump()<<this<<".Replace('"<<theFilterName<<"','"<<theNewName<<"',"<<aFilter<<")";
3707 //=======================================================================
3708 // name : FilterLibrary_i::Save
3709 // Purpose : Save library on disk
3710 //=======================================================================
3711 CORBA::Boolean FilterLibrary_i::Save()
3713 if ( myFileName == 0 || strlen( myFileName ) == 0 )
3716 FILE* aOutFile = fopen( myFileName, "wt" );
3720 LDOM_XmlWriter aWriter( aOutFile );
3721 aWriter.SetIndentation( 2 );
3725 TPythonDump()<<this<<".Save()";
3729 //=======================================================================
3730 // name : FilterLibrary_i::SaveAs
3731 // Purpose : Save library on disk
3732 //=======================================================================
3733 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
3735 myFileName = strdup ( aFileName );
3736 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
3740 //=======================================================================
3741 // name : FilterLibrary_i::IsPresent
3742 // Purpose : Verify whether filter is in library
3743 //=======================================================================
3744 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
3746 return !findFilter( theFilterName, myDoc ).isNull();
3749 //=======================================================================
3750 // name : FilterLibrary_i::NbFilters
3751 // Purpose : Return amount of filters in library
3752 //=======================================================================
3753 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
3755 string_array_var aNames = GetNames( theType );
3756 return aNames->length();
3759 //=======================================================================
3760 // name : FilterLibrary_i::GetNames
3761 // Purpose : Get names of filters from library
3762 //=======================================================================
3763 string_array* FilterLibrary_i::GetNames( ElementType theType )
3765 string_array_var anArray = new string_array;
3766 TColStd_SequenceOfHAsciiString aSeq;
3768 LDOM_Node aSection = getSection( theType, myDoc, false );
3770 if ( !aSection.isNull() )
3772 for ( LDOM_Node aFilter = aSection.getFirstChild();
3773 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3775 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
3776 aSeq.Append( new TCollection_HAsciiString(
3777 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
3781 anArray->length( aSeq.Length() );
3782 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
3783 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
3785 return anArray._retn();
3788 //=======================================================================
3789 // name : FilterLibrary_i::GetAllNames
3790 // Purpose : Get names of filters from library
3791 //=======================================================================
3792 string_array* FilterLibrary_i::GetAllNames()
3794 string_array_var aResArray = new string_array;
3795 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
3797 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
3799 int aPrevLength = aResArray->length();
3800 aResArray->length( aPrevLength + aNames->length() );
3801 for ( int i = 0, n = aNames->length(); i < n; i++ )
3802 aResArray[ aPrevLength + i ] = aNames[ i ];
3805 return aResArray._retn();
3808 //================================================================================
3810 * \brief Return an array of strings corresponding to items of enum FunctorType
3812 //================================================================================
3814 static const char** getFunctNames()
3816 static const char* functName[] = {
3817 // IT's necessary to update this array according to enum FunctorType (SMESH_Filter.idl)
3818 // The order is IMPORTANT !!!
3827 "FT_MaxElementLength2D",
3828 "FT_MaxElementLength3D",
3837 "FT_MultiConnection",
3838 "FT_MultiConnection2D",
3843 "FT_BelongToCylinder",
3844 "FT_BelongToGenSurface",
3847 "FT_BadOrientedVolume",
3848 "FT_BareBorderVolume",
3849 "FT_BareBorderFace",
3850 "FT_OverConstrainedVolume",
3851 "FT_OverConstrainedFace",
3852 "FT_LinearOrQuadratic",
3858 "FT_ConnectedElements",
3868 // check if functName is complete, compilation failure mains that enum FunctorType changed
3869 const int nbFunctors = sizeof(functName) / sizeof(const char*);
3870 int _assert[( nbFunctors == SMESH::FT_Undefined + 1 ) ? 1 : -1 ];
3876 //================================================================================
3878 * \brief Return a string corresponding to an item of enum FunctorType
3880 //================================================================================
3882 const char* SMESH::FunctorTypeToString(SMESH::FunctorType ft)
3884 if ( ft < 0 || ft > SMESH::FT_Undefined )
3885 return "FT_Undefined";
3886 return getFunctNames()[ ft ];
3889 //================================================================================
3891 * \brief Converts a string to FunctorType. This is reverse of FunctorTypeToString()
3893 //================================================================================
3895 SMESH::FunctorType SMESH::StringToFunctorType(const char* str)
3897 std::string name( str + 3 ); // skip "FT_"
3898 const char** functNames = getFunctNames();
3900 for ( ; ft < SMESH::FT_Undefined; ++ft )
3901 if ( name == ( functNames[ft] + 3 ))
3904 //ASSERT( strcmp( str, FunctorTypeToString( SMESH::FunctorType( ft ))) == 0 );
3906 return SMESH::FunctorType( ft );