1 // Copyright (C) 2007-2019 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 classes
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_GroupBase.hxx"
35 #include "SMESHDS_Mesh.hxx"
36 #include "SMESH_Gen_i.hxx"
37 #include "SMESH_Group_i.hxx"
38 #include "SMESH_PythonDump.hxx"
40 #include <SALOMEDS_wrap.hxx>
41 #include <GEOM_wrap.hxx>
43 #include <BRep_Tool.hxx>
44 #include <Geom_CylindricalSurface.hxx>
45 #include <Geom_Plane.hxx>
46 #include <LDOMParser.hxx>
47 #include <LDOMString.hxx>
48 #include <LDOM_Document.hxx>
49 #include <LDOM_Element.hxx>
50 #include <LDOM_Node.hxx>
51 #include <LDOM_XmlWriter.hxx>
52 #include <Precision.hxx>
53 #include <TColStd_ListIteratorOfListOfInteger.hxx>
54 #include <TColStd_ListIteratorOfListOfReal.hxx>
55 #include <TColStd_ListOfInteger.hxx>
56 #include <TColStd_ListOfReal.hxx>
57 #include <TColStd_SequenceOfHAsciiString.hxx>
58 #include <TCollection_HAsciiString.hxx>
59 #include <TopExp_Explorer.hxx>
61 #include <TopoDS_Shape.hxx>
63 using namespace SMESH;
64 using namespace SMESH::Controls;
70 GetPredicate( Predicate_ptr thePredicate )
72 return DownCast<Predicate_i*>(thePredicate);
82 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
84 SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
85 return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
90 toArray( const TColStd_ListOfInteger& aList )
92 SMESH::long_array_var anArray = new SMESH::long_array;
93 anArray->length( aList.Extent() );
94 TColStd_ListIteratorOfListOfInteger anIter( aList );
96 for( ; anIter.More(); anIter.Next() )
97 anArray[ i++ ] = anIter.Value();
99 return anArray._retn();
104 toArray( const TColStd_ListOfReal& aList )
106 SMESH::double_array_var anArray = new SMESH::double_array;
107 anArray->length( aList.Extent() );
108 TColStd_ListIteratorOfListOfReal anIter( aList );
110 for( ; anIter.More(); anIter.Next() )
111 anArray[ i++ ] = anIter.Value();
113 return anArray._retn();
116 static SMESH::Filter::Criterion createCriterion()
118 SMESH::Filter::Criterion aCriterion;
120 aCriterion.Type = FT_Undefined;
121 aCriterion.Compare = FT_Undefined;
122 aCriterion.Threshold = 0;
123 aCriterion.UnaryOp = FT_Undefined;
124 aCriterion.BinaryOp = FT_Undefined;
125 aCriterion.ThresholdStr = "";
126 aCriterion.ThresholdID = "";
127 aCriterion.Tolerance = Precision::Confusion();
128 aCriterion.TypeOfElement = SMESH::ALL;
129 aCriterion.Precision = -1;
134 static TopoDS_Shape getShapeByName( const char* theName )
138 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
139 SALOMEDS::Study::ListOfSObject_var aList = SMESH_Gen_i::getStudyServant()->FindObjectByName( theName, "GEOM" );
140 if ( aList->length() > 0 )
142 CORBA::Object_var anObj = aList[ 0 ]->GetObject();
143 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( anObj );
144 TopoDS_Shape shape = aSMESHGen->GeomObjectToShape( aGeomObj );
145 SALOME::UnRegister( aList ); // UnRegister() objects in aList
149 return TopoDS_Shape();
152 static TopoDS_Shape getShapeByID (const char* theID)
154 if ( theID && strlen( theID ) > 0 ) {
155 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
156 SALOMEDS::SObject_wrap aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID(theID);
157 if ( !aSObj->_is_nil() ) {
158 CORBA::Object_var obj = aSObj->GetObject();
159 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
160 return aSMESHGen->GeomObjectToShape( aGeomObj );
163 return TopoDS_Shape();
166 // static std::string getShapeNameByID (const char* theID)
168 // if ( theID && strlen( theID ) > 0 ) {
169 // SALOMEDS::SObject_wrap aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID(theID);
170 // if ( !aSObj->_is_nil() ) {
171 // CORBA::String_var name = aSObj->GetName();
184 Description : An abstract class for all functors
186 Functor_i::Functor_i():
187 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
189 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
190 //PortableServer::ObjectId_var anObjectId =
191 // SMESH_Gen_i::GetPOA()->activate_object( this );
194 Functor_i::~Functor_i()
196 //TPythonDump()<<this<<".UnRegister()";
199 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
201 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
202 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
205 ElementType Functor_i::GetElementType()
207 return ( ElementType )myFunctorPtr->GetType();
212 Class : NumericalFunctor_i
213 Description : Base class for numerical functors
215 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
217 return myNumericalFunctorPtr->GetValue( theId );
220 CORBA::Boolean NumericalFunctor_i::IsApplicable( CORBA::Long theElementId )
222 return myNumericalFunctorPtr->IsApplicable( theElementId );
225 SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals, CORBA::Boolean isLogarithmic)
227 std::vector<int> nbEvents;
228 std::vector<double> funValues;
229 std::vector<int> elements;
230 myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements,0,isLogarithmic);
232 SMESH::Histogram_var histogram = new SMESH::Histogram;
234 nbIntervals = CORBA::Short( Min( int( nbEvents.size()),
235 int( funValues.size() - 1 )));
236 if ( nbIntervals > 0 )
238 histogram->length( nbIntervals );
239 for ( int i = 0; i < nbIntervals; ++i )
241 HistogramRectangle& rect = histogram[i];
242 rect.nbEvents = nbEvents[i];
243 rect.min = funValues[i];
244 rect.max = funValues[i+1];
247 return histogram._retn();
250 SMESH::Histogram* NumericalFunctor_i::GetLocalHistogram(CORBA::Short nbIntervals,
251 CORBA::Boolean isLogarithmic,
252 SMESH::SMESH_IDSource_ptr object)
254 SMESH::Histogram_var histogram = new SMESH::Histogram;
256 std::vector<int> nbEvents;
257 std::vector<double> funValues;
258 std::vector<int> elements;
260 SMDS_ElemIteratorPtr elemIt;
261 if ( SMESH::DownCast< SMESH_GroupOnFilter_i* >( object ) ||
262 SMESH::DownCast< SMESH::Filter_i* >( object ))
264 elemIt = SMESH_Mesh_i::GetElements( object, GetElementType() );
265 if ( !elemIt ) return histogram._retn();
269 SMESH::SMESH_Mesh_var mesh = object->GetMesh();
270 SMESH::long_array_var objNbElems = object->GetNbElementsByType();
271 SMESH::long_array_var meshNbElems = mesh-> GetNbElementsByType();
272 if ( meshNbElems[ GetElementType() ] !=
273 objNbElems [ GetElementType() ] )
275 elements.reserve( objNbElems[ GetElementType() ]);
276 elemIt = SMESH_Mesh_i::GetElements( object, GetElementType() );
281 while ( elemIt->more() )
282 elements.push_back( elemIt->next()->GetID() );
283 if ( elements.empty() ) return histogram._retn();
286 myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements,0,isLogarithmic);
288 nbIntervals = CORBA::Short( Min( int( nbEvents.size()),
289 int( funValues.size() - 1 )));
290 if ( nbIntervals > 0 )
292 histogram->length( nbIntervals );
293 for ( int i = 0; i < nbIntervals; ++i )
295 HistogramRectangle& rect = histogram[i];
296 rect.nbEvents = nbEvents[i];
297 rect.min = funValues[i];
298 rect.max = funValues[i+1];
301 return histogram._retn();
304 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
306 myNumericalFunctorPtr->SetPrecision( thePrecision );
307 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
310 CORBA::Long NumericalFunctor_i::GetPrecision()
312 return myNumericalFunctorPtr->GetPrecision();
315 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
317 return myNumericalFunctorPtr;
322 Class : SMESH_MinimumAngle
323 Description : Functor for calculation of minimum angle
325 MinimumAngle_i::MinimumAngle_i()
327 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
328 myFunctorPtr = myNumericalFunctorPtr;
331 FunctorType MinimumAngle_i::GetFunctorType()
333 return SMESH::FT_MinimumAngle;
339 Description : Functor for calculating aspect ratio
341 AspectRatio_i::AspectRatio_i()
343 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
344 myFunctorPtr = myNumericalFunctorPtr;
347 FunctorType AspectRatio_i::GetFunctorType()
349 return SMESH::FT_AspectRatio;
354 Class : AspectRatio3D
355 Description : Functor for calculating aspect ratio 3D
357 AspectRatio3D_i::AspectRatio3D_i()
359 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
360 myFunctorPtr = myNumericalFunctorPtr;
363 FunctorType AspectRatio3D_i::GetFunctorType()
365 return SMESH::FT_AspectRatio3D;
371 Description : Functor for calculating warping
373 Warping_i::Warping_i()
375 myNumericalFunctorPtr.reset( new Controls::Warping() );
376 myFunctorPtr = myNumericalFunctorPtr;
379 FunctorType Warping_i::GetFunctorType()
381 return SMESH::FT_Warping;
387 Description : Functor for calculating taper
391 myNumericalFunctorPtr.reset( new Controls::Taper() );
392 myFunctorPtr = myNumericalFunctorPtr;
395 FunctorType Taper_i::GetFunctorType()
397 return SMESH::FT_Taper;
402 Description : Functor for calculating skew in degrees
406 myNumericalFunctorPtr.reset( new Controls::Skew() );
407 myFunctorPtr = myNumericalFunctorPtr;
410 FunctorType Skew_i::GetFunctorType()
412 return SMESH::FT_Skew;
417 Description : Functor for calculating area
421 myNumericalFunctorPtr.reset( new Controls::Area() );
422 myFunctorPtr = myNumericalFunctorPtr;
425 FunctorType Area_i::GetFunctorType()
427 return SMESH::FT_Area;
432 Description : Functor for calculating volume of 3D element
434 Volume3D_i::Volume3D_i()
436 myNumericalFunctorPtr.reset( new Controls::Volume() );
437 myFunctorPtr = myNumericalFunctorPtr;
440 FunctorType Volume3D_i::GetFunctorType()
442 return SMESH::FT_Volume3D;
446 Class : MaxElementLength2D_i
447 Description : Functor for calculating maximum length of 2D element
449 MaxElementLength2D_i::MaxElementLength2D_i()
451 myNumericalFunctorPtr.reset( new Controls::MaxElementLength2D() );
452 myFunctorPtr = myNumericalFunctorPtr;
455 FunctorType MaxElementLength2D_i::GetFunctorType()
457 return SMESH::FT_MaxElementLength2D;
461 Class : MaxElementLength3D_i
462 Description : Functor for calculating maximum length of 3D element
464 MaxElementLength3D_i::MaxElementLength3D_i()
466 myNumericalFunctorPtr.reset( new Controls::MaxElementLength3D() );
467 myFunctorPtr = myNumericalFunctorPtr;
470 FunctorType MaxElementLength3D_i::GetFunctorType()
472 return SMESH::FT_MaxElementLength3D;
477 Description : Functor for calculating length off edge
481 myNumericalFunctorPtr.reset( new Controls::Length() );
482 myFunctorPtr = myNumericalFunctorPtr;
485 FunctorType Length_i::GetFunctorType()
487 return SMESH::FT_Length;
492 Description : Functor for calculating length of edge
494 Length2D_i::Length2D_i()
496 myNumericalFunctorPtr.reset( new Controls::Length2D() );
497 myFunctorPtr = myNumericalFunctorPtr;
500 FunctorType Length2D_i::GetFunctorType()
502 return SMESH::FT_Length2D;
505 SMESH::Length2D::Values* Length2D_i::GetValues()
507 SMESH::Controls::Length2D::TValues aValues;
508 (dynamic_cast<SMESH::Controls::Length2D*>(myFunctorPtr.get()))->GetValues( aValues );
510 long i = 0, iEnd = aValues.size();
512 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
513 aResult->length(iEnd);
515 SMESH::Controls::Length2D::TValues::const_iterator anIter;
516 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
518 const SMESH::Controls::Length2D::Value& aVal = *anIter;
519 SMESH::Length2D::Value &aValue = aResult[ i ];
521 aValue.myLength = aVal.myLength;
522 aValue.myPnt1 = aVal.myPntId[ 0 ];
523 aValue.myPnt2 = aVal.myPntId[ 1 ];
526 return aResult._retn();
532 Description : Functor for calculating length of edge
534 Length3D_i::Length3D_i()
536 myNumericalFunctorPtr.reset( new Controls::Length3D() );
537 myFunctorPtr = myNumericalFunctorPtr;
540 FunctorType Length3D_i::GetFunctorType()
542 return SMESH::FT_Length3D;
545 // SMESH::Length3D::Values* Length3D_i::GetValues()
547 // SMESH::Controls::Length3D::TValues aValues;
548 // (dynamic_cast<SMESH::Controls::Length3D*>(myFunctorPtr.get()))->GetValues( aValues );
550 // long i = 0, iEnd = aValues.size();
552 // SMESH::Length3D::Values_var aResult = new SMESH::Length3D::Values(iEnd);
553 // aResult->length(iEnd);
555 // SMESH::Controls::Length3D::TValues::const_iterator anIter;
556 // for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
558 // const SMESH::Controls::Length3D::Value& aVal = *anIter;
559 // SMESH::Length3D::Value &aValue = aResult[ i ];
561 // aValue.myLength = aVal.myLength;
562 // aValue.myPnt1 = aVal.myPntId[ 0 ];
563 // aValue.myPnt2 = aVal.myPntId[ 1 ];
566 // return aResult._retn();
570 Class : Deflection2D_i
571 Description : Functor for calculating distance between a face and geometry
573 Deflection2D_i::Deflection2D_i()
575 myNumericalFunctorPtr.reset( new Controls::Deflection2D() );
576 myFunctorPtr = myNumericalFunctorPtr;
579 FunctorType Deflection2D_i::GetFunctorType()
581 return SMESH::FT_Deflection2D;
585 Class : MultiConnection_i
586 Description : Functor for calculating number of faces conneted to the edge
588 MultiConnection_i::MultiConnection_i()
590 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
591 myFunctorPtr = myNumericalFunctorPtr;
594 FunctorType MultiConnection_i::GetFunctorType()
596 return SMESH::FT_MultiConnection;
600 Class : BallDiameter_i
601 Description : Functor returning diameter of a ball element
603 BallDiameter_i::BallDiameter_i()
605 myNumericalFunctorPtr.reset( new Controls::BallDiameter() );
606 myFunctorPtr = myNumericalFunctorPtr;
609 FunctorType BallDiameter_i::GetFunctorType()
611 return SMESH::FT_BallDiameter;
615 Class : NodeConnectivityNumber_i
616 Description : Functor returning diameter of a ball element
618 NodeConnectivityNumber_i::NodeConnectivityNumber_i()
620 myNumericalFunctorPtr.reset( new Controls::NodeConnectivityNumber() );
621 myFunctorPtr = myNumericalFunctorPtr;
624 FunctorType NodeConnectivityNumber_i::GetFunctorType()
626 return SMESH::FT_NodeConnectivityNumber;
630 Class : MultiConnection2D_i
631 Description : Functor for calculating number of faces conneted to the edge
633 MultiConnection2D_i::MultiConnection2D_i()
635 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
636 myFunctorPtr = myNumericalFunctorPtr;
639 FunctorType MultiConnection2D_i::GetFunctorType()
641 return SMESH::FT_MultiConnection2D;
644 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
646 SMESH::Controls::MultiConnection2D::MValues aValues;
647 (dynamic_cast<SMESH::Controls::MultiConnection2D*>(myFunctorPtr.get()))->GetValues( aValues );
649 long i = 0, iEnd = aValues.size();
651 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
652 aResult->length(iEnd);
654 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
655 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
657 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
658 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
660 aValue.myPnt1 = aVal.myPntId[ 0 ];
661 aValue.myPnt2 = aVal.myPntId[ 1 ];
662 aValue.myNbConnects = (*anIter).second;
665 return aResult._retn();
675 Description : Base class for all predicates
677 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
679 return myPredicatePtr->IsSatisfy( theId );
682 CORBA::Long Predicate_i::NbSatisfying( SMESH::SMESH_IDSource_ptr obj )
684 SMESH::SMESH_Mesh_var meshVar = obj->GetMesh();
685 const SMDS_Mesh* meshDS = MeshPtr2SMDSMesh( meshVar );
688 myPredicatePtr->SetMesh( meshDS );
690 SMDSAbs_ElementType elemType = SMDSAbs_ElementType( GetElementType() );
693 SMDS_ElemIteratorPtr elemIt =
694 SMESH::DownCast<SMESH_Mesh_i*>( meshVar )->GetElements( obj, GetElementType() );
696 while ( elemIt->more() )
698 const SMDS_MeshElement* e = elemIt->next();
699 if ( e && e->GetType() == elemType )
700 nb += myPredicatePtr->IsSatisfy( e->GetID() );
705 Controls::PredicatePtr Predicate_i::GetPredicate()
707 return myPredicatePtr;
711 Class : BadOrientedVolume_i
712 Description : Verify whether a mesh volume is incorrectly oriented from
713 the point of view of MED convention
715 BadOrientedVolume_i::BadOrientedVolume_i()
717 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
718 myFunctorPtr = myPredicatePtr = control;
721 FunctorType BadOrientedVolume_i::GetFunctorType()
723 return SMESH::FT_BadOrientedVolume;
727 Class : BareBorderVolume_i
728 Description : Verify whether a mesh volume has a free facet without a face on it
730 BareBorderVolume_i::BareBorderVolume_i()
732 Controls::PredicatePtr control( new Controls::BareBorderVolume() );
733 myFunctorPtr = myPredicatePtr = control;
736 FunctorType BareBorderVolume_i::GetFunctorType()
738 return SMESH::FT_BareBorderVolume;
742 Class : BareBorderFace_i
743 Description : Verify whether a mesh face has a free border without an edge on it
745 BareBorderFace_i::BareBorderFace_i()
747 Controls::PredicatePtr control( new Controls::BareBorderFace() );
748 myFunctorPtr = myPredicatePtr = control;
751 FunctorType BareBorderFace_i::GetFunctorType()
753 return SMESH::FT_BareBorderFace;
757 Class : OverConstrainedVolume_i
758 Description : Verify whether a mesh volume has only one facet shared with other volumes
760 OverConstrainedVolume_i::OverConstrainedVolume_i()
762 Controls::PredicatePtr control( new Controls::OverConstrainedVolume() );
763 myFunctorPtr = myPredicatePtr = control;
766 FunctorType OverConstrainedVolume_i::GetFunctorType()
768 return SMESH::FT_OverConstrainedVolume;
772 Class : OverConstrainedFace_i
773 Description : Verify whether a mesh face has only one border shared with other faces
775 OverConstrainedFace_i::OverConstrainedFace_i()
777 Controls::PredicatePtr control( new Controls::OverConstrainedFace() );
778 myFunctorPtr = myPredicatePtr = control;
781 FunctorType OverConstrainedFace_i::GetFunctorType()
783 return SMESH::FT_OverConstrainedFace;
787 Class : BelongToMeshGroup_i
788 Description : Verify whether a mesh element is included into a mesh group
790 BelongToMeshGroup_i::BelongToMeshGroup_i()
792 myBelongToMeshGroup = Controls::BelongToMeshGroupPtr( new Controls::BelongToMeshGroup() );
793 myFunctorPtr = myPredicatePtr = myBelongToMeshGroup;
796 BelongToMeshGroup_i::~BelongToMeshGroup_i()
798 SetGroup( SMESH::SMESH_GroupBase::_nil() );
801 void BelongToMeshGroup_i::SetGroup( SMESH::SMESH_GroupBase_ptr theGroup )
803 if ( myGroup->_is_equivalent( theGroup ))
806 if ( ! myGroup->_is_nil() )
807 myGroup->UnRegister();
809 myGroup = SMESH_GroupBase::_duplicate( theGroup );
811 myBelongToMeshGroup->SetGroup( 0 );
812 if ( SMESH_GroupBase_i* gr_i = SMESH::DownCast< SMESH_GroupBase_i* >( myGroup ))
814 myBelongToMeshGroup->SetGroup( gr_i->GetGroupDS() );
819 void BelongToMeshGroup_i::SetGroupID( const char* theID ) // IOR or StoreName
822 if ( strncmp( "IOR:", myID.c_str(), 4 ) == 0 ) // transient mode, no GUI
824 CORBA::Object_var obj = SMESH_Gen_i::GetORB()->string_to_object( myID.c_str() );
825 SetGroup( SMESH::SMESH_GroupBase::_narrow( obj ));
827 else if ( strncmp( "0:", myID.c_str(), 2 ) == 0 ) // transient mode + GUI
829 SALOMEDS::SObject_wrap aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID( myID.c_str() );
830 if ( !aSObj->_is_nil() ) {
831 CORBA::Object_var obj = aSObj->GetObject();
832 SetGroup( SMESH::SMESH_GroupBase::_narrow( obj ));
835 else if ( !myID.empty() ) // persistent mode
837 myBelongToMeshGroup->SetStoreName( myID );
841 std::string BelongToMeshGroup_i::GetGroupID()
843 if ( myGroup->_is_nil() )
844 SMESH::SMESH_GroupBase_var( GetGroup() );
846 if ( !myGroup->_is_nil() )
847 myID = SMESH_Gen_i::GetORB()->object_to_string( myGroup );
852 SMESH::SMESH_GroupBase_ptr BelongToMeshGroup_i::GetGroup()
854 if ( myGroup->_is_nil() && myBelongToMeshGroup->GetGroup() )
856 // search for a group in a current study
857 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
858 if ( StudyContext* sc = aSMESHGen->GetStudyContext() )
864 ior = sc->getIORbyId( id++ );
865 if ( ior.empty() ) break;
866 CORBA::Object_var obj = aSMESHGen->GetORB()->string_to_object( ior.c_str() );
867 if ( SMESH_GroupBase_i* g_i = SMESH::DownCast<SMESH_GroupBase_i*>( obj ))
868 if ( g_i->GetGroupDS() == myBelongToMeshGroup->GetGroup() )
870 SetGroup( g_i->_this() );
876 return SMESH::SMESH_GroupBase::_duplicate( myGroup );
879 FunctorType BelongToMeshGroup_i::GetFunctorType()
881 return SMESH::FT_BelongToMeshGroup;
885 Class : BelongToGeom_i
886 Description : Predicate for selection on geometrical support
888 BelongToGeom_i::BelongToGeom_i()
890 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
891 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
896 BelongToGeom_i::~BelongToGeom_i()
898 CORBA::string_free( myShapeName );
899 CORBA::string_free( myShapeID );
902 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
904 if ( theGeom->_is_nil() )
906 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
907 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
908 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
909 myBelongToGeomPtr->SetGeom( aLocShape );
910 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
913 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
915 myBelongToGeomPtr->SetGeom( theShape );
918 void BelongToGeom_i::SetElementType(ElementType theType)
920 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
921 TPythonDump()<<this<<".SetElementType("<<theType<<")";
924 FunctorType BelongToGeom_i::GetFunctorType()
926 return SMESH::FT_BelongToGeom;
929 void BelongToGeom_i::SetShapeName( const char* theName )
931 CORBA::string_free( myShapeName );
932 myShapeName = CORBA::string_dup( theName );
933 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
934 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
937 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
939 CORBA::string_free( myShapeName );
940 CORBA::string_free( myShapeID );
941 myShapeName = CORBA::string_dup( theName );
942 myShapeID = CORBA::string_dup( theID );
943 bool hasName = ( theName && theName[0] );
944 bool hasID = ( theID && theID[0] );
947 if ( hasName && hasID )
949 S = getShapeByID( myShapeID );
951 S = getShapeByName( myShapeName );
955 S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
957 myBelongToGeomPtr->SetGeom( S );
960 char* BelongToGeom_i::GetShapeName()
962 return CORBA::string_dup( myShapeName );
965 char* BelongToGeom_i::GetShapeID()
967 return CORBA::string_dup( myShapeID );
970 void BelongToGeom_i::SetTolerance( CORBA::Double theToler )
972 myBelongToGeomPtr->SetTolerance( theToler );
973 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
976 CORBA::Double BelongToGeom_i::GetTolerance()
978 return myBelongToGeomPtr->GetTolerance();
982 Class : BelongToSurface_i
983 Description : Predicate for selection on geometrical support
985 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
987 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
988 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
991 mySurfaceType = theSurfaceType;
994 BelongToSurface_i::~BelongToSurface_i()
996 CORBA::string_free( myShapeName );
997 CORBA::string_free( myShapeID );
1000 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1002 if ( theGeom->_is_nil() )
1004 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1005 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1006 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1008 if ( aLocShape.ShapeType() == TopAbs_FACE )
1010 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
1011 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
1013 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1018 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
1021 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
1023 CORBA::string_free( myShapeName );
1024 myShapeName = CORBA::string_dup( theName );
1025 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1026 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
1029 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
1031 CORBA::string_free( myShapeName );
1032 CORBA::string_free( myShapeID );
1033 myShapeName = CORBA::string_dup( theName );
1034 myShapeID = CORBA::string_dup( theID );
1035 bool hasName = ( theName && theName[0] );
1036 bool hasID = ( theID && theID[0] );
1039 if ( hasName && hasID )
1041 S = getShapeByID( myShapeID );
1043 S = getShapeByName( myShapeName );
1047 S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
1049 myElementsOnSurfacePtr->SetSurface( S, (SMDSAbs_ElementType)theType );
1052 char* BelongToSurface_i::GetShapeName()
1054 return CORBA::string_dup( myShapeName );
1057 char* BelongToSurface_i::GetShapeID()
1059 return CORBA::string_dup( myShapeID );
1062 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
1064 myElementsOnSurfacePtr->SetTolerance( theToler );
1065 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1068 CORBA::Double BelongToSurface_i::GetTolerance()
1070 return myElementsOnSurfacePtr->GetTolerance();
1073 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
1075 myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
1076 TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
1079 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
1081 return myElementsOnSurfacePtr->GetUseBoundaries();
1086 Class : BelongToPlane_i
1087 Description : Verify whether mesh element lie in pointed Geom planar object
1090 BelongToPlane_i::BelongToPlane_i()
1091 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
1095 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1097 BelongToSurface_i::SetSurface( theGeom, theType );
1098 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
1101 FunctorType BelongToPlane_i::GetFunctorType()
1103 return FT_BelongToPlane;
1107 Class : BelongToCylinder_i
1108 Description : Verify whether mesh element lie in pointed Geom planar object
1111 BelongToCylinder_i::BelongToCylinder_i()
1112 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1116 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1118 BelongToSurface_i::SetSurface( theGeom, theType );
1119 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
1122 FunctorType BelongToCylinder_i::GetFunctorType()
1124 return FT_BelongToCylinder;
1128 Class : BelongToGenSurface_i
1129 Description : Verify whether mesh element lie in pointed Geom planar object
1132 BelongToGenSurface_i::BelongToGenSurface_i()
1133 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1137 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1139 if ( theGeom->_is_nil() )
1141 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1142 if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1143 aLocShape.Nullify();
1145 BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1146 TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1149 FunctorType BelongToGenSurface_i::GetFunctorType()
1151 return FT_BelongToGenSurface;
1155 Class : LyingOnGeom_i
1156 Description : Predicate for selection on geometrical support
1158 LyingOnGeom_i::LyingOnGeom_i()
1160 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1161 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1166 LyingOnGeom_i::~LyingOnGeom_i()
1168 CORBA::string_free( myShapeName );
1169 CORBA::string_free( myShapeID );
1172 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1174 if ( theGeom->_is_nil() )
1176 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1177 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1178 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1179 myLyingOnGeomPtr->SetGeom( aLocShape );
1180 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1183 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1185 myLyingOnGeomPtr->SetGeom( theShape );
1188 void LyingOnGeom_i::SetElementType(ElementType theType){
1189 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1190 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1193 FunctorType LyingOnGeom_i::GetFunctorType()
1195 return SMESH::FT_LyingOnGeom;
1198 void LyingOnGeom_i::SetShapeName( const char* theName )
1200 CORBA::string_free( myShapeName );
1201 myShapeName = CORBA::string_dup( theName );
1202 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1203 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1206 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1208 CORBA::string_free( myShapeName );
1209 CORBA::string_free( myShapeID );
1210 myShapeName = CORBA::string_dup( theName );
1211 myShapeID = CORBA::string_dup( theID );
1212 bool hasName = ( theName && theName[0] );
1213 bool hasID = ( theID && theID[0] );
1216 if ( hasName && hasID )
1218 S = getShapeByID( myShapeID );
1220 S = getShapeByName( myShapeName );
1224 S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
1226 myLyingOnGeomPtr->SetGeom( S );
1229 char* LyingOnGeom_i::GetShapeName()
1231 return CORBA::string_dup( myShapeName );
1234 char* LyingOnGeom_i::GetShapeID()
1236 return CORBA::string_dup( myShapeID );
1239 void LyingOnGeom_i::SetTolerance( CORBA::Double theToler )
1241 myLyingOnGeomPtr->SetTolerance( theToler );
1242 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1245 CORBA::Double LyingOnGeom_i::GetTolerance()
1247 return myLyingOnGeomPtr->GetTolerance();
1251 Class : FreeBorders_i
1252 Description : Predicate for free borders
1254 FreeBorders_i::FreeBorders_i()
1256 myPredicatePtr.reset(new Controls::FreeBorders());
1257 myFunctorPtr = myPredicatePtr;
1260 FunctorType FreeBorders_i::GetFunctorType()
1262 return SMESH::FT_FreeBorders;
1267 Description : Predicate for free borders
1269 FreeEdges_i::FreeEdges_i()
1270 : myFreeEdgesPtr( new Controls::FreeEdges() )
1272 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1275 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1277 SMESH::Controls::FreeEdges::TBorders aBorders;
1278 myFreeEdgesPtr->GetBoreders( aBorders );
1280 long i = 0, iEnd = aBorders.size();
1282 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1283 aResult->length(iEnd);
1285 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1286 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1288 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1289 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1291 aBorder.myElemId = aBord.myElemId;
1292 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1293 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1295 return aResult._retn();
1298 FunctorType FreeEdges_i::GetFunctorType()
1300 return SMESH::FT_FreeEdges;
1305 Description : Predicate for free faces
1307 FreeFaces_i::FreeFaces_i()
1309 myPredicatePtr.reset(new Controls::FreeFaces());
1310 myFunctorPtr = myPredicatePtr;
1313 FunctorType FreeFaces_i::GetFunctorType()
1315 return SMESH::FT_FreeFaces;
1320 Description : Predicate for free nodes
1322 FreeNodes_i::FreeNodes_i()
1324 myPredicatePtr.reset(new Controls::FreeNodes());
1325 myFunctorPtr = myPredicatePtr;
1328 FunctorType FreeNodes_i::GetFunctorType()
1330 return SMESH::FT_FreeNodes;
1334 Class : EqualNodes_i
1335 Description : Predicate for Equal nodes
1337 EqualNodes_i::EqualNodes_i()
1339 myCoincidentNodesPtr.reset(new Controls::CoincidentNodes());
1340 myFunctorPtr = myPredicatePtr = myCoincidentNodesPtr;
1343 FunctorType EqualNodes_i::GetFunctorType()
1345 return SMESH::FT_EqualNodes;
1348 void EqualNodes_i::SetTolerance( double tol )
1350 myCoincidentNodesPtr->SetTolerance( tol );
1353 double EqualNodes_i::GetTolerance()
1355 return myCoincidentNodesPtr->GetTolerance();
1359 Class : EqualEdges_i
1360 Description : Predicate for Equal Edges
1362 EqualEdges_i::EqualEdges_i()
1364 myPredicatePtr.reset(new Controls::CoincidentElements1D());
1365 myFunctorPtr = myPredicatePtr;
1368 FunctorType EqualEdges_i::GetFunctorType()
1370 return SMESH::FT_EqualEdges;
1374 Class : EqualFaces_i
1375 Description : Predicate for Equal Faces
1377 EqualFaces_i::EqualFaces_i()
1379 myPredicatePtr.reset(new Controls::CoincidentElements2D());
1380 myFunctorPtr = myPredicatePtr;
1383 FunctorType EqualFaces_i::GetFunctorType()
1385 return SMESH::FT_EqualFaces;
1389 Class : EqualVolumes_i
1390 Description : Predicate for Equal Volumes
1392 EqualVolumes_i::EqualVolumes_i()
1394 myPredicatePtr.reset(new Controls::CoincidentElements3D());
1395 myFunctorPtr = myPredicatePtr;
1398 FunctorType EqualVolumes_i::GetFunctorType()
1400 return SMESH::FT_EqualVolumes;
1405 Class : RangeOfIds_i
1406 Description : Predicate for Range of Ids.
1407 Range may be specified with two ways.
1408 1. Using AddToRange method
1409 2. With SetRangeStr method. Parameter of this method is a string
1410 like as "1,2,3,50-60,63,67,70-"
1413 RangeOfIds_i::RangeOfIds_i()
1415 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1416 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1419 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1421 CORBA::Long iEnd = theIds.length();
1422 for ( CORBA::Long i = 0; i < iEnd; i++ )
1423 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1424 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1427 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1429 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1430 return myRangeOfIdsPtr->SetRangeStr(
1431 TCollection_AsciiString( (Standard_CString)theRange ) );
1434 char* RangeOfIds_i::GetRangeStr()
1436 TCollection_AsciiString aStr;
1437 myRangeOfIdsPtr->GetRangeStr( aStr );
1438 return CORBA::string_dup( aStr.ToCString() );
1441 void RangeOfIds_i::SetElementType( ElementType theType )
1443 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1444 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1447 FunctorType RangeOfIds_i::GetFunctorType()
1449 return SMESH::FT_RangeOfIds;
1453 Class : LinearOrQuadratic_i
1454 Description : Predicate to verify whether a mesh element is linear
1456 LinearOrQuadratic_i::LinearOrQuadratic_i()
1458 myLinearOrQuadraticPtr.reset(new Controls::LinearOrQuadratic());
1459 myFunctorPtr = myPredicatePtr = myLinearOrQuadraticPtr;
1462 void LinearOrQuadratic_i::SetElementType(ElementType theType)
1464 myLinearOrQuadraticPtr->SetType(SMDSAbs_ElementType(theType));
1465 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1468 FunctorType LinearOrQuadratic_i::GetFunctorType()
1470 return SMESH::FT_LinearOrQuadratic;
1474 Class : GroupColor_i
1475 Description : Functor for check color of group to which mesh element belongs to
1477 GroupColor_i::GroupColor_i()
1479 myGroupColorPtr.reset(new Controls::GroupColor());
1480 myFunctorPtr = myPredicatePtr = myGroupColorPtr;
1483 FunctorType GroupColor_i::GetFunctorType()
1485 return SMESH::FT_GroupColor;
1488 void GroupColor_i::SetColorStr( const char* theColor )
1490 myGroupColorPtr->SetColorStr(
1491 TCollection_AsciiString( (Standard_CString)theColor ) );
1492 TPythonDump()<<this<<".SetColorStr('"<<theColor<<"')";
1495 char* GroupColor_i::GetColorStr()
1497 TCollection_AsciiString aStr;
1498 myGroupColorPtr->GetColorStr( aStr );
1499 return CORBA::string_dup( aStr.ToCString() );
1502 void GroupColor_i::SetElementType(ElementType theType)
1504 myGroupColorPtr->SetType(SMDSAbs_ElementType(theType));
1505 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1509 Class : ElemGeomType_i
1510 Description : Predicate check is element has indicated geometry type
1512 ElemGeomType_i::ElemGeomType_i()
1514 myElemGeomTypePtr.reset(new Controls::ElemGeomType());
1515 myFunctorPtr = myPredicatePtr = myElemGeomTypePtr;
1518 void ElemGeomType_i::SetElementType(ElementType theType)
1520 myElemGeomTypePtr->SetType(SMDSAbs_ElementType(theType));
1521 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1524 void ElemGeomType_i::SetGeometryType(GeometryType theType)
1526 myElemGeomTypePtr->SetGeomType(SMDSAbs_GeometryType(theType));
1527 TPythonDump()<<this<<".SetGeometryType("<<theType<<")";
1530 GeometryType ElemGeomType_i::GetGeometryType() const
1532 return (GeometryType)myElemGeomTypePtr->GetGeomType();
1535 FunctorType ElemGeomType_i::GetFunctorType()
1537 return SMESH::FT_ElemGeomType;
1541 Class : ElemEntityType_i
1542 Description : Predicate check is element has indicated entity type
1544 ElemEntityType_i::ElemEntityType_i()
1546 myElemEntityTypePtr.reset(new Controls::ElemEntityType());
1547 myFunctorPtr = myPredicatePtr = myElemEntityTypePtr;
1550 void ElemEntityType_i::SetElementType(ElementType theType)
1552 myElemEntityTypePtr->SetType(SMDSAbs_ElementType(theType));
1553 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1556 void ElemEntityType_i::SetEntityType(EntityType theEntityType)
1558 myElemEntityTypePtr->SetElemEntityType(SMDSAbs_EntityType (theEntityType));
1559 TPythonDump()<<this<<".SetEntityType("<<theEntityType<<")";
1561 EntityType ElemEntityType_i::GetEntityType() const
1563 return (EntityType) myElemEntityTypePtr->GetElemEntityType();
1566 FunctorType ElemEntityType_i::GetFunctorType()
1568 return SMESH::FT_EntityType;
1572 Class : CoplanarFaces_i
1573 Description : Returns true if a mesh face is a coplanar neighbour to a given one
1575 CoplanarFaces_i::CoplanarFaces_i()
1577 myCoplanarFacesPtr.reset(new Controls::CoplanarFaces());
1578 myFunctorPtr = myPredicatePtr = myCoplanarFacesPtr;
1581 void CoplanarFaces_i::SetFace ( CORBA::Long theFaceID )
1583 myCoplanarFacesPtr->SetFace(theFaceID);
1584 TPythonDump()<<this<<".SetFace("<<theFaceID<<")";
1587 void CoplanarFaces_i::SetTolerance( CORBA::Double theToler )
1589 myCoplanarFacesPtr->SetTolerance(theToler);
1590 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1593 CORBA::Long CoplanarFaces_i::GetFace () const
1595 return myCoplanarFacesPtr->GetFace();
1598 char* CoplanarFaces_i::GetFaceAsString () const
1600 TCollection_AsciiString str(Standard_Integer(myCoplanarFacesPtr->GetFace()));
1601 return CORBA::string_dup( str.ToCString() );
1604 CORBA::Double CoplanarFaces_i::GetTolerance() const
1606 return myCoplanarFacesPtr->GetTolerance();
1609 FunctorType CoplanarFaces_i::GetFunctorType()
1611 return SMESH::FT_CoplanarFaces;
1615 * Class : ConnectedElements_i
1616 * Description : Returns true if an element is connected via other elements to the element
1617 * located at a given point.
1619 ConnectedElements_i::ConnectedElements_i()
1621 myConnectedElementsPtr.reset(new Controls::ConnectedElements());
1622 myFunctorPtr = myPredicatePtr = myConnectedElementsPtr;
1625 FunctorType ConnectedElements_i::GetFunctorType()
1627 return FT_ConnectedElements;
1630 void ConnectedElements_i::SetElementType( ElementType theType )
1632 myConnectedElementsPtr->SetType( SMDSAbs_ElementType( theType ));
1633 TPythonDump() << this << ".SetElementType( " << theType << " )";
1636 void ConnectedElements_i::SetPoint( CORBA::Double x, CORBA::Double y, CORBA::Double z )
1638 myConnectedElementsPtr->SetPoint( x,y,z );
1640 TPythonDump() << this << ".SetPoint( " << x << ", " << y << ", " << z << " )";
1643 void ConnectedElements_i::SetVertex( GEOM::GEOM_Object_ptr vertex )
1644 throw (SALOME::SALOME_Exception)
1646 TopoDS_Shape shape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( vertex );
1647 if ( shape.IsNull() )
1648 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetVertex(): NULL Vertex",
1649 SALOME::BAD_PARAM );
1651 TopExp_Explorer v( shape, TopAbs_VERTEX );
1653 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetVertex(): empty vertex",
1654 SALOME::BAD_PARAM );
1656 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( v.Current() ));
1657 myConnectedElementsPtr->SetPoint( p.X(), p.Y(), p.Z() );
1659 CORBA::String_var id = vertex->GetStudyEntry();
1660 myVertexID = id.in();
1662 TPythonDump() << this << ".SetVertex( " << vertex << " )";
1665 void ConnectedElements_i::SetNode ( CORBA::Long nodeID )
1666 throw (SALOME::SALOME_Exception)
1669 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetNode(): nodeID must be > 0",
1670 SALOME::BAD_PARAM );
1672 myConnectedElementsPtr->SetNode( nodeID );
1674 TPythonDump() << this << ".SetNode( " << nodeID << " )";
1678 * \brief This is a comfort method for Filter dialog
1680 void ConnectedElements_i::SetThreshold ( const char* threshold,
1681 SMESH::ConnectedElements::ThresholdType type )
1682 throw (SALOME::SALOME_Exception)
1685 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetThreshold(): NULL threshold",
1686 SALOME::BAD_PARAM );
1689 case SMESH::ConnectedElements::POINT: // read 3 node coordinates ///////////////////
1691 std::vector< double > xyz;
1696 while ( *threshold &&
1697 *threshold != '+' &&
1698 *threshold != '-' &&
1699 !isdigit( *threshold ))
1703 // read a coordinate
1704 xyz.push_back( strtod( threshold, &endptr ));
1705 if ( threshold == endptr )
1707 xyz.resize( xyz.size() - 1 );
1712 while ( xyz.size() < 3 );
1714 if ( xyz.size() < 3 )
1715 THROW_SALOME_CORBA_EXCEPTION
1716 ( "ConnectedElements_i::SetThreshold(): invalid point coordinates", SALOME::BAD_PARAM );
1718 SetPoint( xyz[0], xyz[1], xyz[2] );
1721 case SMESH::ConnectedElements::VERTEX: // get a VERTEX by its entry /////////////////
1723 SALOMEDS::SObject_wrap sobj = SMESH_Gen_i::getStudyServant()->FindObjectID( threshold );
1724 if ( sobj->_is_nil() )
1725 THROW_SALOME_CORBA_EXCEPTION
1726 ( "ConnectedElements_i::SetThreshold(): invalid vertex study entry", SALOME::BAD_PARAM );
1727 CORBA::Object_var obj = sobj->GetObject();
1728 GEOM::GEOM_Object_var vertex = GEOM::GEOM_Object::_narrow( obj );
1729 if ( vertex->_is_nil() )
1730 THROW_SALOME_CORBA_EXCEPTION
1731 ( "ConnectedElements_i::SetThreshold(): no GEOM_Object in SObject", SALOME::BAD_PARAM );
1732 SetVertex( vertex );
1735 case SMESH::ConnectedElements::NODE: // read a node ID ////////////////////////////
1738 int id = strtol( threshold, &endptr, 10 );
1739 if ( threshold == endptr )
1740 THROW_SALOME_CORBA_EXCEPTION
1741 ( "ConnectedElements_i::SetThreshold(): invalid node ID", SALOME::BAD_PARAM );
1746 THROW_SALOME_CORBA_EXCEPTION
1747 ( "ConnectedElements_i::SetThreshold(): invalid ThresholdType", SALOME::BAD_PARAM );
1751 char* ConnectedElements_i::GetThreshold ( SMESH::ConnectedElements::ThresholdType& type )
1753 std::string threshold;
1754 if ( !myVertexID.empty() )
1756 threshold = myVertexID;
1757 type = SMESH::ConnectedElements::VERTEX;
1761 std::vector<double> xyz = myConnectedElementsPtr->GetPoint();
1762 if ( xyz.size() == 3 )
1764 threshold = SMESH_Comment( xyz[0] ) << "; " << xyz[1] << "; " << xyz[2];
1765 type = SMESH::ConnectedElements::POINT;
1769 threshold = SMESH_Comment( myConnectedElementsPtr->GetNode() );
1770 type = SMESH::ConnectedElements::NODE;
1773 return CORBA::string_dup( threshold.c_str() );
1777 Class : Comparator_i
1778 Description : Base class for comparators
1780 Comparator_i::Comparator_i():
1781 myNumericalFunctor( NULL )
1784 Comparator_i::~Comparator_i()
1786 if ( myNumericalFunctor )
1787 myNumericalFunctor->UnRegister();
1790 void Comparator_i::SetMargin( CORBA::Double theValue )
1792 myComparatorPtr->SetMargin( theValue );
1793 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1796 CORBA::Double Comparator_i::GetMargin()
1798 return myComparatorPtr->GetMargin();
1801 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1803 if ( myNumericalFunctor )
1804 myNumericalFunctor->UnRegister();
1806 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1808 if ( myNumericalFunctor )
1810 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1811 myNumericalFunctor->Register();
1812 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1816 Controls::ComparatorPtr Comparator_i::GetComparator()
1818 return myComparatorPtr;
1821 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1823 return myNumericalFunctor;
1829 Description : Comparator "<"
1831 LessThan_i::LessThan_i()
1833 myComparatorPtr.reset( new Controls::LessThan() );
1834 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1837 FunctorType LessThan_i::GetFunctorType()
1839 return SMESH::FT_LessThan;
1845 Description : Comparator ">"
1847 MoreThan_i::MoreThan_i()
1849 myComparatorPtr.reset( new Controls::MoreThan() );
1850 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1853 FunctorType MoreThan_i::GetFunctorType()
1855 return SMESH::FT_MoreThan;
1861 Description : Comparator "="
1863 EqualTo_i::EqualTo_i()
1864 : myEqualToPtr( new Controls::EqualTo() )
1866 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1869 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1871 myEqualToPtr->SetTolerance( theToler );
1872 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1875 CORBA::Double EqualTo_i::GetTolerance()
1877 return myEqualToPtr->GetTolerance();
1880 FunctorType EqualTo_i::GetFunctorType()
1882 return SMESH::FT_EqualTo;
1886 Class : LogicalNOT_i
1887 Description : Logical NOT predicate
1889 LogicalNOT_i::LogicalNOT_i():
1890 myLogicalNOTPtr( new Controls::LogicalNOT() ),
1893 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1896 LogicalNOT_i::~LogicalNOT_i()
1899 myPredicate->UnRegister();
1902 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1905 myPredicate->UnRegister();
1907 myPredicate = SMESH::GetPredicate(thePredicate);
1910 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1911 myPredicate->Register();
1912 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1916 FunctorType LogicalNOT_i::GetFunctorType()
1918 return SMESH::FT_LogicalNOT;
1921 Predicate_i* LogicalNOT_i::GetPredicate_i()
1929 Class : LogicalBinary_i
1930 Description : Base class for binary logical predicate
1932 LogicalBinary_i::LogicalBinary_i()
1933 : myPredicate1( NULL ),
1934 myPredicate2( NULL )
1937 LogicalBinary_i::~LogicalBinary_i()
1940 myPredicate1->UnRegister();
1943 myPredicate2->UnRegister();
1946 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1949 myPredicate1->SetMesh( theMesh );
1952 myPredicate2->SetMesh( theMesh );
1955 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1958 myPredicate1->UnRegister();
1960 myPredicate1 = SMESH::GetPredicate(thePredicate);
1962 if ( myPredicate1 ){
1963 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1964 myPredicate1->Register();
1965 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1969 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1972 myPredicate2->UnRegister();
1974 myPredicate2 = SMESH::GetPredicate(thePredicate);
1976 if ( myPredicate2 ){
1977 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1978 myPredicate2->Register();
1979 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1983 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1985 return myLogicalBinaryPtr;
1988 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1990 return myPredicate1;
1992 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1994 return myPredicate2;
1999 Class : LogicalAND_i
2000 Description : Logical AND
2002 LogicalAND_i::LogicalAND_i()
2004 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
2005 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
2008 FunctorType LogicalAND_i::GetFunctorType()
2010 return SMESH::FT_LogicalAND;
2016 Description : Logical OR
2018 LogicalOR_i::LogicalOR_i()
2020 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
2021 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
2024 FunctorType LogicalOR_i::GetFunctorType()
2026 return SMESH::FT_LogicalOR;
2034 FilterManager_i::FilterManager_i()
2035 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
2037 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
2038 //PortableServer::ObjectId_var anObjectId =
2039 // SMESH_Gen_i::GetPOA()->activate_object( this );
2043 FilterManager_i::~FilterManager_i()
2045 //TPythonDump()<<this<<".UnRegister()";
2049 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
2051 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
2052 SMESH::MinimumAngle_var anObj = aServant->_this();
2053 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
2054 return anObj._retn();
2058 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
2060 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
2061 SMESH::AspectRatio_var anObj = aServant->_this();
2062 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
2063 return anObj._retn();
2067 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
2069 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
2070 SMESH::AspectRatio3D_var anObj = aServant->_this();
2071 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
2072 return anObj._retn();
2076 Warping_ptr FilterManager_i::CreateWarping()
2078 SMESH::Warping_i* aServant = new SMESH::Warping_i();
2079 SMESH::Warping_var anObj = aServant->_this();
2080 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
2081 return anObj._retn();
2085 Taper_ptr FilterManager_i::CreateTaper()
2087 SMESH::Taper_i* aServant = new SMESH::Taper_i();
2088 SMESH::Taper_var anObj = aServant->_this();
2089 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
2090 return anObj._retn();
2094 Skew_ptr FilterManager_i::CreateSkew()
2096 SMESH::Skew_i* aServant = new SMESH::Skew_i();
2097 SMESH::Skew_var anObj = aServant->_this();
2098 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
2099 return anObj._retn();
2103 Area_ptr FilterManager_i::CreateArea()
2105 SMESH::Area_i* aServant = new SMESH::Area_i();
2106 SMESH::Area_var anObj = aServant->_this();
2107 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
2108 return anObj._retn();
2112 Volume3D_ptr FilterManager_i::CreateVolume3D()
2114 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
2115 SMESH::Volume3D_var anObj = aServant->_this();
2116 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
2117 return anObj._retn();
2121 MaxElementLength2D_ptr FilterManager_i::CreateMaxElementLength2D()
2123 SMESH::MaxElementLength2D_i* aServant = new SMESH::MaxElementLength2D_i();
2124 SMESH::MaxElementLength2D_var anObj = aServant->_this();
2125 TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength2D()";
2126 return anObj._retn();
2130 MaxElementLength3D_ptr FilterManager_i::CreateMaxElementLength3D()
2132 SMESH::MaxElementLength3D_i* aServant = new SMESH::MaxElementLength3D_i();
2133 SMESH::MaxElementLength3D_var anObj = aServant->_this();
2134 TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength3D()";
2135 return anObj._retn();
2139 Length_ptr FilterManager_i::CreateLength()
2141 SMESH::Length_i* aServant = new SMESH::Length_i();
2142 SMESH::Length_var anObj = aServant->_this();
2143 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
2144 return anObj._retn();
2147 Length2D_ptr FilterManager_i::CreateLength2D()
2149 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
2150 SMESH::Length2D_var anObj = aServant->_this();
2151 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
2152 return anObj._retn();
2155 Length3D_ptr FilterManager_i::CreateLength3D()
2157 SMESH::Length3D_i* aServant = new SMESH::Length3D_i();
2158 SMESH::Length3D_var anObj = aServant->_this();
2159 TPythonDump()<<aServant<<" = "<<this<<".CreateLength3D()";
2160 return anObj._retn();
2163 Deflection2D_ptr FilterManager_i::CreateDeflection2D()
2165 SMESH::Deflection2D_i* aServant = new SMESH::Deflection2D_i();
2166 SMESH::Deflection2D_var anObj = aServant->_this();
2167 TPythonDump()<<aServant<<" = "<<this<<".CreateDeflection2D()";
2168 return anObj._retn();
2171 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
2173 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
2174 SMESH::MultiConnection_var anObj = aServant->_this();
2175 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
2176 return anObj._retn();
2179 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
2181 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
2182 SMESH::MultiConnection2D_var anObj = aServant->_this();
2183 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
2184 return anObj._retn();
2187 BallDiameter_ptr FilterManager_i::CreateBallDiameter()
2189 SMESH::BallDiameter_i* aServant = new SMESH::BallDiameter_i();
2190 SMESH::BallDiameter_var anObj = aServant->_this();
2191 TPythonDump()<<aServant<<" = "<<this<<".CreateBallDiameter()";
2192 return anObj._retn();
2195 NodeConnectivityNumber_ptr FilterManager_i::CreateNodeConnectivityNumber()
2197 SMESH::NodeConnectivityNumber_i* aServant = new SMESH::NodeConnectivityNumber_i();
2198 SMESH::NodeConnectivityNumber_var anObj = aServant->_this();
2199 TPythonDump()<<aServant<<" = "<<this<<".CreateNodeConnectivityNumber()";
2200 return anObj._retn();
2203 BelongToMeshGroup_ptr FilterManager_i::CreateBelongToMeshGroup()
2205 SMESH::BelongToMeshGroup_i* aServant = new SMESH::BelongToMeshGroup_i();
2206 SMESH::BelongToMeshGroup_var anObj = aServant->_this();
2207 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToMeshGroup()";
2208 return anObj._retn();
2211 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
2213 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
2214 SMESH::BelongToGeom_var anObj = aServant->_this();
2215 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
2216 return anObj._retn();
2219 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
2221 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
2222 SMESH::BelongToPlane_var anObj = aServant->_this();
2223 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
2224 return anObj._retn();
2227 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
2229 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
2230 SMESH::BelongToCylinder_var anObj = aServant->_this();
2231 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
2232 return anObj._retn();
2235 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
2237 SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
2238 SMESH::BelongToGenSurface_var anObj = aServant->_this();
2239 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
2240 return anObj._retn();
2243 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
2245 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
2246 SMESH::LyingOnGeom_var anObj = aServant->_this();
2247 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
2248 return anObj._retn();
2251 CoplanarFaces_ptr FilterManager_i::CreateCoplanarFaces()
2253 SMESH::CoplanarFaces_i* aServant = new SMESH::CoplanarFaces_i();
2254 SMESH::CoplanarFaces_var anObj = aServant->_this();
2255 TPythonDump()<<aServant<<" = "<<this<<".CreateCoplanarFaces()";
2256 return anObj._retn();
2259 ConnectedElements_ptr FilterManager_i::CreateConnectedElements()
2261 SMESH::ConnectedElements_i* aServant = new SMESH::ConnectedElements_i();
2262 SMESH::ConnectedElements_var anObj = aServant->_this();
2263 TPythonDump()<<aServant<<" = "<<this<<".CreateConnectedElements()";
2264 return anObj._retn();
2267 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
2269 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
2270 SMESH::FreeBorders_var anObj = aServant->_this();
2271 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
2272 return anObj._retn();
2275 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
2277 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
2278 SMESH::FreeEdges_var anObj = aServant->_this();
2279 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
2280 return anObj._retn();
2283 FreeFaces_ptr FilterManager_i::CreateFreeFaces()
2285 SMESH::FreeFaces_i* aServant = new SMESH::FreeFaces_i();
2286 SMESH::FreeFaces_var anObj = aServant->_this();
2287 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeFaces()";
2288 return anObj._retn();
2291 FreeNodes_ptr FilterManager_i::CreateFreeNodes()
2293 SMESH::FreeNodes_i* aServant = new SMESH::FreeNodes_i();
2294 SMESH::FreeNodes_var anObj = aServant->_this();
2295 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeNodes()";
2296 return anObj._retn();
2299 EqualNodes_ptr FilterManager_i::CreateEqualNodes()
2301 SMESH::EqualNodes_i* aServant = new SMESH::EqualNodes_i();
2302 SMESH::EqualNodes_var anObj = aServant->_this();
2303 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualNodes()";
2304 return anObj._retn();
2307 EqualEdges_ptr FilterManager_i::CreateEqualEdges()
2309 SMESH::EqualEdges_i* aServant = new SMESH::EqualEdges_i();
2310 SMESH::EqualEdges_var anObj = aServant->_this();
2311 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualEdges()";
2312 return anObj._retn();
2314 EqualFaces_ptr FilterManager_i::CreateEqualFaces()
2316 SMESH::EqualFaces_i* aServant = new SMESH::EqualFaces_i();
2317 SMESH::EqualFaces_var anObj = aServant->_this();
2318 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualFaces()";
2319 return anObj._retn();
2321 EqualVolumes_ptr FilterManager_i::CreateEqualVolumes()
2323 SMESH::EqualVolumes_i* aServant = new SMESH::EqualVolumes_i();
2324 SMESH::EqualVolumes_var anObj = aServant->_this();
2325 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualVolumes()";
2326 return anObj._retn();
2329 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
2331 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
2332 SMESH::RangeOfIds_var anObj = aServant->_this();
2333 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
2334 return anObj._retn();
2337 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
2339 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
2340 SMESH::BadOrientedVolume_var anObj = aServant->_this();
2341 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
2342 return anObj._retn();
2345 BareBorderVolume_ptr FilterManager_i::CreateBareBorderVolume()
2347 SMESH::BareBorderVolume_i* aServant = new SMESH::BareBorderVolume_i();
2348 SMESH::BareBorderVolume_var anObj = aServant->_this();
2349 TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderVolume()";
2350 return anObj._retn();
2353 BareBorderFace_ptr FilterManager_i::CreateBareBorderFace()
2355 SMESH::BareBorderFace_i* aServant = new SMESH::BareBorderFace_i();
2356 SMESH::BareBorderFace_var anObj = aServant->_this();
2357 TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderFace()";
2358 return anObj._retn();
2361 OverConstrainedVolume_ptr FilterManager_i::CreateOverConstrainedVolume()
2363 SMESH::OverConstrainedVolume_i* aServant = new SMESH::OverConstrainedVolume_i();
2364 SMESH::OverConstrainedVolume_var anObj = aServant->_this();
2365 TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedVolume()";
2366 return anObj._retn();
2369 OverConstrainedFace_ptr FilterManager_i::CreateOverConstrainedFace()
2371 SMESH::OverConstrainedFace_i* aServant = new SMESH::OverConstrainedFace_i();
2372 SMESH::OverConstrainedFace_var anObj = aServant->_this();
2373 TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedFace()";
2374 return anObj._retn();
2377 LessThan_ptr FilterManager_i::CreateLessThan()
2379 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
2380 SMESH::LessThan_var anObj = aServant->_this();
2381 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
2382 return anObj._retn();
2385 MoreThan_ptr FilterManager_i::CreateMoreThan()
2387 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
2388 SMESH::MoreThan_var anObj = aServant->_this();
2389 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
2390 return anObj._retn();
2393 EqualTo_ptr FilterManager_i::CreateEqualTo()
2395 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
2396 SMESH::EqualTo_var anObj = aServant->_this();
2397 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
2398 return anObj._retn();
2401 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
2403 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
2404 SMESH::LogicalNOT_var anObj = aServant->_this();
2405 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
2406 return anObj._retn();
2409 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
2411 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
2412 SMESH::LogicalAND_var anObj = aServant->_this();
2413 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
2414 return anObj._retn();
2417 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
2419 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
2420 SMESH::LogicalOR_var anObj = aServant->_this();
2421 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
2422 return anObj._retn();
2425 LinearOrQuadratic_ptr FilterManager_i::CreateLinearOrQuadratic()
2427 SMESH::LinearOrQuadratic_i* aServant = new SMESH::LinearOrQuadratic_i();
2428 SMESH::LinearOrQuadratic_var anObj = aServant->_this();
2429 TPythonDump()<<aServant<<" = "<<this<<".CreateLinearOrQuadratic()";
2430 return anObj._retn();
2433 GroupColor_ptr FilterManager_i::CreateGroupColor()
2435 SMESH::GroupColor_i* aServant = new SMESH::GroupColor_i();
2436 SMESH::GroupColor_var anObj = aServant->_this();
2437 TPythonDump()<<aServant<<" = "<<this<<".CreateGroupColor()";
2438 return anObj._retn();
2441 ElemGeomType_ptr FilterManager_i::CreateElemGeomType()
2443 SMESH::ElemGeomType_i* aServant = new SMESH::ElemGeomType_i();
2444 SMESH::ElemGeomType_var anObj = aServant->_this();
2445 TPythonDump()<<aServant<<" = "<<this<<".CreateElemGeomType()";
2446 return anObj._retn();
2449 ElemEntityType_ptr FilterManager_i::CreateElemEntityType()
2451 SMESH::ElemEntityType_i* aServant = new SMESH::ElemEntityType_i();
2452 SMESH::ElemEntityType_var anObj = aServant->_this();
2453 TPythonDump()<<aServant<<" = "<<this<<".CreateElemEntityType()";
2454 return anObj._retn();
2457 Filter_ptr FilterManager_i::CreateFilter()
2459 SMESH::Filter_i* aServant = new SMESH::Filter_i();
2460 SMESH::Filter_var anObj = aServant->_this();
2461 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
2462 return anObj._retn();
2465 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
2467 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
2468 SMESH::FilterLibrary_var anObj = aServant->_this();
2469 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary('"<<aFileName<<"')";
2470 return anObj._retn();
2473 FilterLibrary_ptr FilterManager_i::CreateLibrary()
2475 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
2476 SMESH::FilterLibrary_var anObj = aServant->_this();
2477 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
2478 return anObj._retn();
2481 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
2483 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
2484 return remove( aFileName ) ? false : true;
2487 //=============================================================================
2489 * SMESH_Gen_i::CreateFilterManager
2491 * Create filter manager
2493 //=============================================================================
2495 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
2497 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2498 SMESH::FilterManager_var anObj = aFilter->_this();
2499 return anObj._retn();
2507 //=======================================================================
2508 // name : Filter_i::Filter_i
2509 // Purpose : Constructor
2510 //=======================================================================
2511 Filter_i::Filter_i()
2512 : myPredicate( NULL )
2515 //=======================================================================
2516 // name : Filter_i::~Filter_i
2517 // Purpose : Destructor
2518 //=======================================================================
2519 Filter_i::~Filter_i()
2522 myPredicate->UnRegister();
2524 if(!CORBA::is_nil(myMesh))
2525 myMesh->UnRegister();
2531 //=======================================================================
2532 // name : Filter_i::SetPredicate
2533 // Purpose : Set predicate
2534 //=======================================================================
2535 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
2538 myPredicate->UnRegister();
2540 myPredicate = SMESH::GetPredicate(thePredicate);
2544 myFilter.SetPredicate( myPredicate->GetPredicate() );
2545 myPredicate->Register();
2546 if ( const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh))
2547 myPredicate->GetPredicate()->SetMesh( aMesh );
2548 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
2550 NotifyerAndWaiter::Modified();
2553 //=======================================================================
2554 // name : Filter_i::GetElementType
2555 // Purpose : Get entity type
2556 //=======================================================================
2557 SMESH::ElementType Filter_i::GetElementType()
2559 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
2562 //=======================================================================
2563 // name : Filter_i::SetMesh
2564 // Purpose : Set mesh
2565 //=======================================================================
2568 SetMesh( SMESH_Mesh_ptr theMesh )
2570 if(!CORBA::is_nil(theMesh))
2571 theMesh->Register();
2573 if(!CORBA::is_nil(myMesh))
2574 myMesh->UnRegister();
2576 myMesh = SMESH_Mesh::_duplicate( theMesh );
2577 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
2580 if ( const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2581 myPredicate->GetPredicate()->SetMesh( aMesh );
2588 return GetElementsId(myMesh);
2591 //=======================================================================
2592 // name : Filter_i::GetElementsId
2593 // Purpose : Get ids of entities
2594 //=======================================================================
2597 GetElementsId( Predicate_i* thePredicate,
2598 const SMDS_Mesh* theMesh,
2599 Controls::Filter::TIdSequence& theSequence )
2602 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
2607 GetElementsId( Predicate_i* thePredicate,
2608 SMESH_Mesh_ptr theMesh,
2609 Controls::Filter::TIdSequence& theSequence )
2612 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2613 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
2618 GetElementsId( SMESH_Mesh_ptr theMesh )
2620 SMESH::long_array_var anArray = new SMESH::long_array;
2621 if(!CORBA::is_nil(theMesh) && myPredicate){
2623 Controls::Filter::TIdSequence aSequence;
2624 GetElementsId(myPredicate,theMesh,aSequence);
2625 long i = 0, iEnd = aSequence.size();
2626 anArray->length( iEnd );
2627 for ( ; i < iEnd; i++ )
2628 anArray[ i ] = aSequence[i];
2630 return anArray._retn();
2635 GetElementsIdFromParts( const ListOfIDSources& theParts )
2637 SMESH::long_array_var array = new SMESH::long_array;
2638 if ( theParts.length() > 0 && myPredicate )
2640 SMESH_Mesh_ptr mesh = theParts[0]->GetMesh();
2642 const SMDS_Mesh* meshDS = MeshPtr2SMDSMesh( mesh );
2643 Controls::Filter::TIdSequence totalSequence;
2644 for ( CORBA::ULong i = 0; i < theParts.length(); ++i )
2646 if ( SMESH::Filter_i* filter = SMESH::DownCast<SMESH::Filter_i*>( theParts[i] ))
2647 filter->SetMesh( mesh );
2648 SMDS_ElemIteratorPtr iter = SMESH_Mesh_i::GetElements( theParts[i], GetElementType() );
2649 if ( iter && meshDS )
2651 Controls::Filter::TIdSequence sequence;
2652 Controls::Filter::GetElementsId( meshDS, myPredicate->GetPredicate(), sequence, iter );
2653 totalSequence.insert( totalSequence.end(), sequence.begin(), sequence.end() );
2656 array->length( totalSequence.size() );
2657 for ( size_t i = 0; i < totalSequence.size(); ++i )
2658 array[ i ] = totalSequence[ i ];
2660 return array._retn();
2663 //=============================================================================
2665 * \brief Returns number of mesh elements per each \a EntityType
2667 //=============================================================================
2669 SMESH::long_array* ::Filter_i::GetMeshInfo()
2671 SMESH::long_array_var aRes = new SMESH::long_array();
2672 aRes->length(SMESH::Entity_Last);
2673 for (int i = 0; i < SMESH::Entity_Last; i++)
2676 if ( !CORBA::is_nil(myMesh) && myPredicate )
2678 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2679 SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2680 while ( it->more() )
2682 const SMDS_MeshElement* anElem = it->next();
2683 if ( myPredicate->IsSatisfy( anElem->GetID() ) )
2684 aRes[ anElem->GetEntityType() ]++;
2688 return aRes._retn();
2691 //=============================================================================
2693 * \brief Returns number of mesh elements of each \a ElementType
2695 //=============================================================================
2697 SMESH::long_array* ::Filter_i::GetNbElementsByType()
2699 SMESH::long_array_var aRes = new SMESH::long_array();
2700 aRes->length(SMESH::NB_ELEMENT_TYPES);
2701 for (int i = 0; i < SMESH::NB_ELEMENT_TYPES; i++)
2704 if ( !CORBA::is_nil(myMesh) && myPredicate ) {
2705 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2706 SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2707 CORBA::Long& nbElems = aRes[ GetElementType() ];
2708 while ( it->more() )
2710 const SMDS_MeshElement* anElem = it->next();
2711 if ( myPredicate->IsSatisfy( anElem->GetID() ) )
2716 return aRes._retn();
2720 //================================================================================
2722 * \brief Return GetElementType() within an array
2723 * Implement SMESH_IDSource interface
2725 //================================================================================
2727 SMESH::array_of_ElementType* Filter_i::GetTypes()
2729 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
2731 // check if any element passes through the filter
2732 if ( !CORBA::is_nil(myMesh) && myPredicate )
2734 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2735 SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2736 bool satisfies = false;
2737 while ( !satisfies && it->more() )
2738 satisfies = myPredicate->IsSatisfy( it->next()->GetID() );
2741 types[0] = GetElementType();
2744 return types._retn();
2747 //=======================================================================
2748 //function : GetMesh
2749 //purpose : Returns mesh
2750 //=======================================================================
2752 SMESH::SMESH_Mesh_ptr Filter_i::GetMesh()
2754 return SMESH_Mesh::_duplicate( myMesh );
2757 //=======================================================================
2758 //function : GetVtkUgStream
2759 //purpose : Return data vtk unstructured grid (not implemented)
2760 //=======================================================================
2762 SALOMEDS::TMPFile* Filter_i::GetVtkUgStream()
2764 SALOMEDS::TMPFile_var SeqFile;
2765 return SeqFile._retn();
2767 //=======================================================================
2768 // name : getCriteria
2769 // Purpose : Retrieve criterions from predicate
2770 //=======================================================================
2771 static inline void getPrediacates( Predicate_i* thePred,
2772 std::vector<Predicate_i*> & thePredVec )
2774 const int aFType = thePred->GetFunctorType();
2780 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2781 getPrediacates( aPred, thePredVec );
2787 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2788 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2789 getPrediacates( aPred1, thePredVec );
2790 getPrediacates( aPred2, thePredVec );
2795 thePredVec.push_back( thePred );
2798 //=======================================================================
2799 // name : getCriteria
2800 // Purpose : Retrieve criterions from predicate
2801 //=======================================================================
2802 static inline bool getCriteria( Predicate_i* thePred,
2803 SMESH::Filter::Criteria_out theCriteria )
2805 const int aFType = thePred->GetFunctorType();
2811 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2812 getCriteria( aPred, theCriteria );
2813 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2820 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2821 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2822 if ( !getCriteria( aPred1, theCriteria ) )
2824 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2825 return getCriteria( aPred2, theCriteria );
2831 // resize theCriteria
2832 CORBA::ULong i = theCriteria->length();
2833 theCriteria->length( i + 1 );
2834 theCriteria[ i ] = createCriterion();
2836 // set members of the added Criterion
2838 theCriteria[ i ].Type = aFType;
2839 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
2843 case FT_FreeBorders:
2846 case FT_LinearOrQuadratic:
2850 case FT_EqualVolumes:
2851 case FT_BadOrientedVolume:
2852 case FT_BareBorderVolume:
2853 case FT_BareBorderFace:
2854 case FT_OverConstrainedVolume:
2855 case FT_OverConstrainedFace:
2859 case FT_BelongToMeshGroup:
2861 BelongToMeshGroup_i* aPred = dynamic_cast<BelongToMeshGroup_i*>( thePred );
2862 SMESH::SMESH_GroupBase_var grp = aPred->GetGroup();
2863 if ( !grp->_is_nil() )
2865 theCriteria[ i ].ThresholdStr = grp->GetName();
2866 theCriteria[ i ].ThresholdID = aPred->GetGroupID().c_str();
2870 case FT_BelongToGeom:
2872 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
2873 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2874 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2875 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2878 case FT_BelongToPlane:
2879 case FT_BelongToCylinder:
2880 case FT_BelongToGenSurface:
2882 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
2883 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2884 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2885 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2888 case FT_LyingOnGeom:
2890 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
2891 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2892 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2893 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2896 case FT_CoplanarFaces:
2898 CoplanarFaces_i* aPred = dynamic_cast<CoplanarFaces_i*>( thePred );
2899 theCriteria[ i ].ThresholdID = aPred->GetFaceAsString();
2900 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2903 case FT_ConnectedElements:
2905 ConnectedElements_i* aPred = dynamic_cast<ConnectedElements_i*>( thePred );
2906 SMESH::ConnectedElements::ThresholdType type;
2907 CORBA::String_var threshold = aPred->GetThreshold( type );
2909 case SMESH::ConnectedElements::POINT:
2910 theCriteria[ i ].ThresholdStr = threshold; break;
2911 case SMESH::ConnectedElements::VERTEX:
2912 theCriteria[ i ].ThresholdID = threshold; break;
2913 case SMESH::ConnectedElements::NODE:
2914 theCriteria[ i ].Threshold = atof( threshold.in() ); break;
2921 EqualNodes_i* aPred = dynamic_cast<EqualNodes_i*>( thePred );
2922 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2927 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
2928 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
2935 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
2936 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
2937 theCriteria[ i ].Compare = aFType;
2938 theCriteria[ i ].Threshold = aCompar->GetMargin();
2939 if ( aFType == FT_EqualTo )
2941 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
2942 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
2948 GroupColor_i* aPred = dynamic_cast<GroupColor_i*>( thePred );
2949 theCriteria[ i ].ThresholdStr = aPred->GetColorStr();
2952 case FT_ElemGeomType:
2954 ElemGeomType_i* aPred = dynamic_cast<ElemGeomType_i*>( thePred );
2955 theCriteria[ i ].Threshold = (double)aPred->GetGeometryType();
2960 ElemEntityType_i* aPred = dynamic_cast<ElemEntityType_i*>( thePred );
2961 theCriteria[ i ].Threshold = (double)aPred->GetEntityType();
2969 //=======================================================================
2970 // name : Filter_i::GetCriteria
2971 // Purpose : Retrieve criterions from predicate
2972 //=======================================================================
2973 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2975 theCriteria = new SMESH::Filter::Criteria;
2976 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2979 //=======================================================================
2980 // name : Filter_i::SetCriteria
2981 // Purpose : Create new predicate and set criterions in it
2982 //=======================================================================
2983 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2985 SetPredicate( SMESH::Predicate::_nil() );
2987 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2988 FilterManager_ptr aFilterMgr = aFilter->_this();
2990 // CREATE two lists ( PREDICATES and LOG OP )
2993 TPythonDump()<<"aCriteria = []";
2994 std::list<SMESH::Predicate_ptr> aPredicates;
2995 std::list<int> aBinaries;
2996 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2998 int aCriterion = theCriteria[ i ].Type;
2999 int aCompare = theCriteria[ i ].Compare;
3000 double aThreshold = theCriteria[ i ].Threshold;
3001 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
3002 const char* aThresholdID = theCriteria[ i ].ThresholdID;
3003 int aUnary = theCriteria[ i ].UnaryOp;
3004 int aBinary = theCriteria[ i ].BinaryOp;
3005 double aTolerance = theCriteria[ i ].Tolerance;
3006 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
3007 long aPrecision = theCriteria[ i ].Precision;
3011 pd << "aCriterion = SMESH.Filter.Criterion("
3012 << aCriterion << ", "
3014 << aThreshold << ", '"
3015 << aThresholdStr << "', '"
3016 << aThresholdID << "', "
3019 << aTolerance << ", "
3020 << aTypeOfElem << ", "
3021 << aPrecision << ")";
3025 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
3026 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
3028 switch ( aCriterion )
3032 case SMESH::FT_MultiConnection:
3033 aFunctor = aFilterMgr->CreateMultiConnection();
3035 case SMESH::FT_MultiConnection2D:
3036 aFunctor = aFilterMgr->CreateMultiConnection2D();
3038 case SMESH::FT_Length:
3039 aFunctor = aFilterMgr->CreateLength();
3041 case SMESH::FT_Length2D:
3042 aFunctor = aFilterMgr->CreateLength2D();
3044 case SMESH::FT_Length3D:
3045 aFunctor = aFilterMgr->CreateLength3D();
3047 case SMESH::FT_Deflection2D:
3048 aFunctor = aFilterMgr->CreateDeflection2D();
3050 case SMESH::FT_AspectRatio:
3051 aFunctor = aFilterMgr->CreateAspectRatio();
3053 case SMESH::FT_AspectRatio3D:
3054 aFunctor = aFilterMgr->CreateAspectRatio3D();
3056 case SMESH::FT_Warping:
3057 aFunctor = aFilterMgr->CreateWarping();
3059 case SMESH::FT_MinimumAngle:
3060 aFunctor = aFilterMgr->CreateMinimumAngle();
3062 case SMESH::FT_Taper:
3063 aFunctor = aFilterMgr->CreateTaper();
3065 case SMESH::FT_Skew:
3066 aFunctor = aFilterMgr->CreateSkew();
3068 case SMESH::FT_Area:
3069 aFunctor = aFilterMgr->CreateArea();
3071 case SMESH::FT_Volume3D:
3072 aFunctor = aFilterMgr->CreateVolume3D();
3074 case SMESH::FT_MaxElementLength2D:
3075 aFunctor = aFilterMgr->CreateMaxElementLength2D();
3077 case SMESH::FT_MaxElementLength3D:
3078 aFunctor = aFilterMgr->CreateMaxElementLength3D();
3080 case SMESH::FT_BallDiameter:
3081 aFunctor = aFilterMgr->CreateBallDiameter();
3083 case SMESH::FT_NodeConnectivityNumber:
3084 aFunctor = aFilterMgr->CreateNodeConnectivityNumber();
3089 case SMESH::FT_FreeBorders:
3090 aPredicate = aFilterMgr->CreateFreeBorders();
3092 case SMESH::FT_FreeEdges:
3093 aPredicate = aFilterMgr->CreateFreeEdges();
3095 case SMESH::FT_FreeFaces:
3096 aPredicate = aFilterMgr->CreateFreeFaces();
3098 case SMESH::FT_FreeNodes:
3099 aPredicate = aFilterMgr->CreateFreeNodes();
3101 case SMESH::FT_EqualNodes:
3103 SMESH::EqualNodes_ptr pred = aFilterMgr->CreateEqualNodes();
3104 pred->SetTolerance( aTolerance );
3108 case SMESH::FT_EqualEdges:
3109 aPredicate = aFilterMgr->CreateEqualEdges();
3111 case SMESH::FT_EqualFaces:
3112 aPredicate = aFilterMgr->CreateEqualFaces();
3114 case SMESH::FT_EqualVolumes:
3115 aPredicate = aFilterMgr->CreateEqualVolumes();
3117 case SMESH::FT_BelongToMeshGroup:
3119 SMESH::BelongToMeshGroup_ptr tmpPred = aFilterMgr->CreateBelongToMeshGroup();
3120 tmpPred->SetGroupID( aThresholdID );
3121 aPredicate = tmpPred;
3124 case SMESH::FT_BelongToGeom:
3126 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
3127 tmpPred->SetElementType( aTypeOfElem );
3128 tmpPred->SetShape( aThresholdID, aThresholdStr );
3129 tmpPred->SetTolerance( aTolerance );
3130 aPredicate = tmpPred;
3133 case SMESH::FT_BelongToPlane:
3134 case SMESH::FT_BelongToCylinder:
3135 case SMESH::FT_BelongToGenSurface:
3137 SMESH::BelongToSurface_ptr tmpPred;
3138 switch ( aCriterion ) {
3139 case SMESH::FT_BelongToPlane:
3140 tmpPred = aFilterMgr->CreateBelongToPlane(); break;
3141 case SMESH::FT_BelongToCylinder:
3142 tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
3144 tmpPred = aFilterMgr->CreateBelongToGenSurface();
3146 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
3147 tmpPred->SetTolerance( aTolerance );
3148 aPredicate = tmpPred;
3151 case SMESH::FT_LyingOnGeom:
3153 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
3154 tmpPred->SetElementType( aTypeOfElem );
3155 tmpPred->SetShape( aThresholdID, aThresholdStr );
3156 tmpPred->SetTolerance( aTolerance );
3157 aPredicate = tmpPred;
3160 case SMESH::FT_RangeOfIds:
3162 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
3163 tmpPred->SetRangeStr( aThresholdStr );
3164 tmpPred->SetElementType( aTypeOfElem );
3165 aPredicate = tmpPred;
3168 case SMESH::FT_BadOrientedVolume:
3170 aPredicate = aFilterMgr->CreateBadOrientedVolume();
3173 case SMESH::FT_BareBorderVolume:
3175 aPredicate = aFilterMgr->CreateBareBorderVolume();
3178 case SMESH::FT_BareBorderFace:
3180 aPredicate = aFilterMgr->CreateBareBorderFace();
3183 case SMESH::FT_OverConstrainedVolume:
3185 aPredicate = aFilterMgr->CreateOverConstrainedVolume();
3188 case SMESH::FT_OverConstrainedFace:
3190 aPredicate = aFilterMgr->CreateOverConstrainedFace();
3193 case SMESH::FT_LinearOrQuadratic:
3195 SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
3196 tmpPred->SetElementType( aTypeOfElem );
3197 aPredicate = tmpPred;
3200 case SMESH::FT_GroupColor:
3202 SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor();
3203 tmpPred->SetElementType( aTypeOfElem );
3204 tmpPred->SetColorStr( aThresholdStr );
3205 aPredicate = tmpPred;
3208 case SMESH::FT_ElemGeomType:
3210 SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType();
3211 tmpPred->SetElementType( aTypeOfElem );
3212 tmpPred->SetGeometryType( (GeometryType)(int)(aThreshold + 0.5) );
3213 aPredicate = tmpPred;
3216 case SMESH::FT_EntityType:
3218 SMESH::ElemEntityType_ptr tmpPred = aFilterMgr->CreateElemEntityType();
3219 tmpPred->SetElementType( aTypeOfElem );
3220 tmpPred->SetEntityType( EntityType( (int (aThreshold + 0.5))));
3221 aPredicate = tmpPred;
3224 case SMESH::FT_CoplanarFaces:
3226 SMESH::CoplanarFaces_ptr tmpPred = aFilterMgr->CreateCoplanarFaces();
3227 tmpPred->SetFace( atol (aThresholdID ));
3228 tmpPred->SetTolerance( aTolerance );
3229 aPredicate = tmpPred;
3232 case SMESH::FT_ConnectedElements:
3234 SMESH::ConnectedElements_ptr tmpPred = aFilterMgr->CreateConnectedElements();
3235 if ( strlen( aThresholdID ) > 0 ) // shape ID
3236 tmpPred->SetThreshold( aThresholdID, SMESH::ConnectedElements::VERTEX );
3237 else if ( strlen( aThresholdStr ) > 0 ) // point coords
3238 tmpPred->SetThreshold( aThresholdStr, SMESH::ConnectedElements::POINT );
3239 else if ( aThreshold >= 1 )
3240 tmpPred->SetNode( (CORBA::Long) aThreshold ); // node ID
3241 tmpPred->SetElementType( aTypeOfElem );
3242 aPredicate = tmpPred;
3251 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
3253 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
3255 if ( aCompare == SMESH::FT_LessThan )
3256 aComparator = aFilterMgr->CreateLessThan();
3257 else if ( aCompare == SMESH::FT_MoreThan )
3258 aComparator = aFilterMgr->CreateMoreThan();
3259 else if ( aCompare == SMESH::FT_EqualTo )
3260 aComparator = aFilterMgr->CreateEqualTo();
3264 aComparator->SetNumFunctor( aFunctor );
3265 aComparator->SetMargin( aThreshold );
3267 if ( aCompare == FT_EqualTo )
3269 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
3270 anEqualTo->SetTolerance( aTolerance );
3273 aPredicate = aComparator;
3275 aFunctor->SetPrecision( aPrecision );
3279 if ( aUnary == FT_LogicalNOT )
3281 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
3282 aNotPred->SetPredicate( aPredicate );
3283 aPredicate = aNotPred;
3287 aPredicates.push_back( aPredicate );
3288 aBinaries.push_back( aBinary );
3289 pd <<"aCriteria.append(aCriterion)";
3292 TPythonDump pd; pd<<this<<".SetCriteria(aCriteria)";
3294 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
3296 // combine all "AND" operations
3298 std::list<SMESH::Predicate_ptr> aResList;
3300 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
3301 std::list<int>::iterator aBinaryIter;
3303 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
3304 int aPrevBinary = SMESH::FT_Undefined;
3305 if ( !aBinaries.empty() )
3306 aBinaries.back() = SMESH::FT_Undefined;
3308 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
3309 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
3310 ++aPredIter, ++aBinaryIter )
3312 int aCurrBinary = *aBinaryIter;
3314 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
3316 if ( aPrevBinary == SMESH::FT_LogicalAND )
3319 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
3320 aBinaryPred->SetPredicate1( aPrevPredicate );
3321 aBinaryPred->SetPredicate2( *aPredIter );
3322 aCurrPred = aBinaryPred;
3325 aCurrPred = *aPredIter;
3327 if ( aCurrBinary != SMESH::FT_LogicalAND )
3328 aResList.push_back( aCurrPred );
3330 aPrevPredicate = aCurrPred;
3331 aPrevBinary = aCurrBinary;
3334 // combine all "OR" operations
3336 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
3338 if ( aResList.size() == 1 )
3339 aResPredicate = *aResList.begin();
3340 else if ( aResList.size() > 1 )
3342 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
3343 aResPredicate = *anIter;
3345 for ( ; anIter != aResList.end(); ++anIter )
3347 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
3348 aBinaryPred->SetPredicate1( aResPredicate );
3349 aBinaryPred->SetPredicate2( *anIter );
3350 aResPredicate = aBinaryPred;
3354 SetPredicate( aResPredicate );
3355 if ( !aResPredicate->_is_nil() )
3356 aResPredicate->UnRegister();
3358 return !aResPredicate->_is_nil();
3361 //=======================================================================
3362 // name : Filter_i::GetPredicate_i
3363 // Purpose : Get implementation of predicate
3364 //=======================================================================
3365 Predicate_i* Filter_i::GetPredicate_i()
3370 //=======================================================================
3371 // name : Filter_i::GetPredicate
3372 // Purpose : Get predicate
3373 //=======================================================================
3374 Predicate_ptr Filter_i::GetPredicate()
3376 if ( myPredicate == 0 )
3377 return SMESH::Predicate::_nil();
3380 SMESH::Predicate_var anObj = myPredicate->_this();
3381 // if ( SMESH::Functor_i* fun = SMESH::DownCast<SMESH::Functor_i*>( anObj ))
3382 // TPythonDump() << fun << " = " << this << ".GetPredicate()";
3383 return anObj._retn();
3387 //================================================================================
3389 * \brief Find groups it depends on
3391 //================================================================================
3393 void Filter_i::FindBaseObjects()
3395 // release current groups
3396 for ( size_t i = 0; i < myBaseGroups.size(); ++i )
3397 if ( myBaseGroups[i] )
3399 myBaseGroups[i]->RemoveModifWaiter( this );
3400 myBaseGroups[i]->UnRegister();
3403 // remember new groups
3404 myBaseGroups.clear();
3407 std::vector<Predicate_i*> predicates;
3408 getPrediacates( myPredicate, predicates );
3409 for ( size_t i = 0; i < predicates.size(); ++i )
3410 if ( BelongToMeshGroup_i* bmg = dynamic_cast< BelongToMeshGroup_i* >( predicates[i] ))
3412 SMESH::SMESH_GroupBase_var g = bmg->GetGroup();
3413 SMESH_GroupBase_i* g_i = SMESH::DownCast< SMESH_GroupBase_i*>( g );
3416 g_i->AddModifWaiter( this );
3418 myBaseGroups.push_back( g_i );
3424 //================================================================================
3426 * \brief When notified on removal of myBaseGroups[i], remove a reference to a
3427 * group from a predicate
3429 //================================================================================
3431 void Filter_i::OnBaseObjModified(NotifyerAndWaiter* group, bool removed)
3434 return; // a GroupOnFilter holding this filter is notified automatically
3438 std::vector<Predicate_i*> predicates;
3439 getPrediacates( myPredicate, predicates );
3440 for ( size_t i = 0; i < predicates.size(); ++i )
3441 if ( BelongToMeshGroup_i* bmg = dynamic_cast< BelongToMeshGroup_i* >( predicates[i] ))
3443 SMESH::SMESH_GroupBase_var g = bmg->GetGroup();
3444 SMESH_GroupBase_i* g_i = SMESH::DownCast< SMESH_GroupBase_i*>( g );
3447 bmg->SetGroup( SMESH::SMESH_GroupBase::_nil() );
3448 bmg->SetGroupID( "" );
3453 FindBaseObjects(); // release and update myBaseGroups;
3460 #define ATTR_TYPE "type"
3461 #define ATTR_COMPARE "compare"
3462 #define ATTR_THRESHOLD "threshold"
3463 #define ATTR_UNARY "unary"
3464 #define ATTR_BINARY "binary"
3465 #define ATTR_THRESHOLD_STR "threshold_str"
3466 #define ATTR_TOLERANCE "tolerance"
3467 #define ATTR_ELEMENT_TYPE "ElementType"
3469 //=======================================================================
3471 // Purpose : Convert bool to LDOMString
3472 //=======================================================================
3473 static inline LDOMString toString( CORBA::Boolean val )
3475 return val ? "logical not" : "";
3478 //=======================================================================
3480 // Purpose : Convert LDOMString to bool
3481 //=======================================================================
3482 static inline bool toBool( const LDOMString& theStr )
3484 return theStr.equals( "logical not" );
3487 //=======================================================================
3489 // Purpose : Convert double to LDOMString
3490 //=======================================================================
3491 static inline LDOMString toString( CORBA::Double val )
3494 sprintf( a, "%e", val );
3495 return LDOMString( a );
3498 //=======================================================================
3500 // Purpose : Convert LDOMString to double
3501 //=======================================================================
3502 static inline double toDouble( const LDOMString& theStr )
3504 return atof( theStr.GetString() );
3507 //=======================================================================
3509 // Purpose : Convert functor type to LDOMString
3510 //=======================================================================
3511 static inline LDOMString toString( CORBA::Long theType )
3515 case FT_AspectRatio : return "Aspect ratio";
3516 case FT_Warping : return "Warping";
3517 case FT_MinimumAngle : return "Minimum angle";
3518 case FT_Taper : return "Taper";
3519 case FT_Skew : return "Skew";
3520 case FT_Area : return "Area";
3521 case FT_Volume3D : return "Volume3D";
3522 case FT_MaxElementLength2D : return "Max element length 2D";
3523 case FT_MaxElementLength3D : return "Max element length 3D";
3524 case FT_BelongToMeshGroup : return "Belong to Mesh Group";
3525 case FT_BelongToGeom : return "Belong to Geom";
3526 case FT_BelongToPlane : return "Belong to Plane";
3527 case FT_BelongToCylinder : return "Belong to Cylinder";
3528 case FT_BelongToGenSurface : return "Belong to Generic Surface";
3529 case FT_LyingOnGeom : return "Lying on Geom";
3530 case FT_BadOrientedVolume : return "Bad Oriented Volume";
3531 case FT_BareBorderVolume : return "Volumes with bare border";
3532 case FT_BareBorderFace : return "Faces with bare border";
3533 case FT_OverConstrainedVolume : return "Over-constrained Volumes";
3534 case FT_OverConstrainedFace : return "Over-constrained Faces";
3535 case FT_RangeOfIds : return "Range of IDs";
3536 case FT_FreeBorders : return "Free borders";
3537 case FT_FreeEdges : return "Free edges";
3538 case FT_FreeFaces : return "Free faces";
3539 case FT_FreeNodes : return "Free nodes";
3540 case FT_EqualNodes : return "Equal nodes";
3541 case FT_EqualEdges : return "Equal edges";
3542 case FT_EqualFaces : return "Equal faces";
3543 case FT_EqualVolumes : return "Equal volumes";
3544 case FT_MultiConnection : return "Borders at multi-connections";
3545 case FT_MultiConnection2D : return "Borders at multi-connections 2D";
3546 case FT_Length : return "Length";
3547 case FT_Length2D : return "Length 2D";
3548 case FT_Length3D : return "Length 3D";
3549 case FT_Deflection2D : return "Deflection 2D";
3550 case FT_LessThan : return "Less than";
3551 case FT_MoreThan : return "More than";
3552 case FT_EqualTo : return "Equal to";
3553 case FT_LogicalNOT : return "Not";
3554 case FT_LogicalAND : return "And";
3555 case FT_LogicalOR : return "Or";
3556 case FT_GroupColor : return "Color of Group";
3557 case FT_LinearOrQuadratic : return "Linear or Quadratic";
3558 case FT_ElemGeomType : return "Element geometry type";
3559 case FT_EntityType : return "Entity type";
3560 case FT_Undefined : return "";
3561 default : return "";
3565 //=======================================================================
3566 // name : toFunctorType
3567 // Purpose : Convert LDOMString to functor type
3568 //=======================================================================
3569 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
3571 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
3572 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
3573 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
3574 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
3575 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
3576 else if ( theStr.equals( "Area" ) ) return FT_Area;
3577 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
3578 else if ( theStr.equals( "Max element length 2D" ) ) return FT_MaxElementLength2D;
3579 else if ( theStr.equals( "Max element length 3D" ) ) return FT_MaxElementLength3D;
3580 else if ( theStr.equals( "Belong to Mesh Group" ) ) return FT_BelongToMeshGroup;
3581 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
3582 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
3583 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
3584 else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface;
3585 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
3586 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
3587 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
3588 else if ( theStr.equals( "Free faces" ) ) return FT_FreeFaces;
3589 else if ( theStr.equals( "Free nodes" ) ) return FT_FreeNodes;
3590 else if ( theStr.equals( "Equal nodes" ) ) return FT_EqualNodes;
3591 else if ( theStr.equals( "Equal edges" ) ) return FT_EqualEdges;
3592 else if ( theStr.equals( "Equal faces" ) ) return FT_EqualFaces;
3593 else if ( theStr.equals( "Equal volumes" ) ) return FT_EqualVolumes;
3594 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
3595 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
3596 else if ( theStr.equals( "Length" ) ) return FT_Length;
3597 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
3598 // else if ( theStr.equals( "Length3D" ) ) return FT_Length3D;
3599 else if ( theStr.equals( "Deflection" ) ) return FT_Deflection2D;
3600 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
3601 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
3602 else if ( theStr.equals( "Volumes with bare border" ) ) return FT_BareBorderVolume;
3603 else if ( theStr.equals( "Faces with bare border" ) ) return FT_BareBorderFace;
3604 else if ( theStr.equals( "Over-constrained Volumes" ) ) return FT_OverConstrainedVolume;
3605 else if ( theStr.equals( "Over-constrained Faces" ) ) return FT_OverConstrainedFace;
3606 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
3607 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
3608 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
3609 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
3610 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
3611 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
3612 else if ( theStr.equals( "Color of Group" ) ) return FT_GroupColor;
3613 else if ( theStr.equals( "Linear or Quadratic" ) ) return FT_LinearOrQuadratic;
3614 else if ( theStr.equals( "Element geometry type" ) ) return FT_ElemGeomType;
3615 else if ( theStr.equals( "Entity type" ) ) return FT_EntityType;
3616 else if ( theStr.equals( "" ) ) return FT_Undefined;
3617 else return FT_Undefined;
3620 //=======================================================================
3621 // name : toFunctorType
3622 // Purpose : Convert LDOMString to value of ElementType enumeration
3623 //=======================================================================
3624 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
3626 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
3627 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
3628 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
3629 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
3630 else return SMESH::ALL;
3633 //=======================================================================
3635 // Purpose : Convert ElementType to string
3636 //=======================================================================
3637 static inline LDOMString toString( const SMESH::ElementType theType )
3641 case SMESH::NODE : return "NODE";
3642 case SMESH::EDGE : return "EDGE";
3643 case SMESH::FACE : return "FACE";
3644 case SMESH::VOLUME : return "VOLUME";
3645 case SMESH::ALL : return "ALL";
3646 default : return "";
3650 //=======================================================================
3651 // name : findFilter
3652 // Purpose : Find filter in document
3653 //=======================================================================
3654 static LDOM_Element findFilter( const char* theFilterName,
3655 const LDOM_Document& theDoc,
3656 LDOM_Node* theParent = 0 )
3658 LDOM_Element aRootElement = theDoc.getDocumentElement();
3659 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
3660 return LDOM_Element();
3662 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
3663 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
3665 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
3666 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3668 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
3669 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
3670 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
3672 if ( theParent != 0 )
3673 *theParent = aTypeNode;
3674 return (LDOM_Element&)aFilter;
3678 return LDOM_Element();
3681 //=======================================================================
3682 // name : getSectionName
3683 // Purpose : Get name of section of filters
3684 //=======================================================================
3685 static const char* getSectionName( const ElementType theType )
3689 case SMESH::NODE : return "Filters for nodes";
3690 case SMESH::EDGE : return "Filters for edges";
3691 case SMESH::FACE : return "Filters for faces";
3692 case SMESH::VOLUME : return "Filters for volumes";
3693 case SMESH::ALL : return "Filters for elements";
3694 default : return "";
3698 //=======================================================================
3699 // name : getSection
3700 // Purpose : Create section for filters corresponding to the entity type
3701 //=======================================================================
3702 static LDOM_Node getSection( const ElementType theType,
3703 LDOM_Document& theDoc,
3704 const bool toCreate = false )
3706 LDOM_Element aRootElement = theDoc.getDocumentElement();
3707 if ( aRootElement.isNull() )
3711 bool anExist = false;
3712 const char* aSectionName = getSectionName( theType );
3713 if ( strcmp( aSectionName, "" ) == 0 )
3716 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
3718 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
3720 aNode = aSections.item( i );
3721 LDOM_Element& anItem = ( LDOM_Element& )aNode;
3722 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
3729 // Create new section if necessary
3734 LDOM_Element aNewItem = theDoc.createElement( "section" );
3735 aNewItem.setAttribute( "name", aSectionName );
3736 aRootElement.appendChild( aNewItem );
3746 //=======================================================================
3747 // name : createFilterItem
3748 // Purpose : Create filter item or LDOM document
3749 //=======================================================================
3750 static LDOM_Element createFilterItem( const char* theName,
3751 SMESH::Filter_ptr theFilter,
3752 LDOM_Document& theDoc )
3754 // create new filter in document
3755 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
3756 aFilterItem.setAttribute( "name", theName );
3758 // save filter criterions
3759 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3761 if ( !theFilter->GetCriteria( aCriteria ) )
3762 return LDOM_Element();
3764 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
3766 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
3768 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
3769 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
3770 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
3771 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
3772 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
3774 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
3775 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
3776 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
3777 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
3779 aFilterItem.appendChild( aCriterionItem );
3785 //=======================================================================
3786 // name : FilterLibrary_i::FilterLibrary_i
3787 // Purpose : Constructor
3788 //=======================================================================
3789 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
3791 myFileName = CORBA::string_dup( theFileName );
3792 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
3793 myFilterMgr = aFilterMgr->_this();
3797 // Try to use existing library file
3798 bool anExists = false;
3799 if ( !aParser.parse( myFileName ) )
3801 myDoc = aParser.getDocument();
3804 // Create a new XML document if it doesn't exist
3806 myDoc = LDOM_Document::createDocument( LDOMString() );
3808 LDOM_Element aRootElement = myDoc.getDocumentElement();
3809 if ( aRootElement.isNull() )
3811 // If the existing document is empty --> try to create a new one
3813 myDoc = LDOM_Document::createDocument( LDOMString() );
3817 //=======================================================================
3818 // name : FilterLibrary_i::FilterLibrary_i
3819 // Purpose : Constructor
3820 //=======================================================================
3821 FilterLibrary_i::FilterLibrary_i()
3824 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
3825 myFilterMgr = aFilter->_this();
3827 myDoc = LDOM_Document::createDocument( LDOMString() );
3830 FilterLibrary_i::~FilterLibrary_i()
3832 CORBA::string_free( myFileName );
3833 //TPythonDump()<<this<<".UnRegister()";
3836 //=======================================================================
3837 // name : FilterLibrary_i::Copy
3838 // Purpose : Create filter and initialize it with values from library
3839 //=======================================================================
3840 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
3842 Filter_ptr aRes = Filter::_nil();
3843 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
3845 if ( aFilter.isNull() )
3848 std::list<SMESH::Filter::Criterion> aCriteria;
3850 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
3851 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
3853 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
3855 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
3856 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
3857 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
3858 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
3859 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
3861 SMESH::Filter::Criterion aCriterion = createCriterion();
3863 aCriterion.Type = toFunctorType( aTypeStr );
3864 aCriterion.Compare = toFunctorType( aCompareStr );
3865 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
3866 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
3868 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
3870 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
3872 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3873 ? val : atof( str.GetString() );
3875 str = aCrit->getAttribute( ATTR_TOLERANCE );
3876 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3877 ? val : atof( str.GetString() );
3879 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
3880 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
3883 sprintf( a, "%d", val );
3884 aCriterion.ThresholdStr = CORBA::string_dup( a );
3887 aCriterion.ThresholdStr = str.GetString();
3889 aCriteria.push_back( aCriterion );
3892 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
3893 aCriteriaVar->length( aCriteria.size() );
3896 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
3898 for( ; anIter != aCriteria.end(); ++anIter )
3899 aCriteriaVar[ i++ ] = *anIter;
3901 aRes = myFilterMgr->CreateFilter();
3902 aRes->SetCriteria( aCriteriaVar.inout() );
3904 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
3909 //=======================================================================
3910 // name : FilterLibrary_i::SetFileName
3911 // Purpose : Set file name for library
3912 //=======================================================================
3913 void FilterLibrary_i::SetFileName( const char* theFileName )
3915 CORBA::string_free( myFileName );
3916 myFileName = CORBA::string_dup( theFileName );
3917 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
3920 //=======================================================================
3921 // name : FilterLibrary_i::GetFileName
3922 // Purpose : Get file name of library
3923 //=======================================================================
3924 char* FilterLibrary_i::GetFileName()
3926 return CORBA::string_dup( myFileName );
3929 //=======================================================================
3930 // name : FilterLibrary_i::Add
3931 // Purpose : Add new filter to library
3932 //=======================================================================
3933 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
3935 // if filter already in library or entry filter is null do nothing
3936 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3937 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
3940 // get section corresponding to the filter type
3941 ElementType anEntType = theFilter->GetElementType();
3943 LDOM_Node aSection = getSection( anEntType, myDoc, true );
3944 if ( aSection.isNull() )
3947 // create filter item
3948 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
3949 if ( aFilterItem.isNull() )
3953 aSection.appendChild( aFilterItem );
3954 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3955 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
3960 //=======================================================================
3961 // name : FilterLibrary_i::Add
3962 // Purpose : Add new filter to library
3963 //=======================================================================
3964 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
3966 // if filter already in library or entry filter is null do nothing
3967 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3968 if ( !aFilterNode.isNull() )
3971 LDOM_Node aSection = getSection( theType, myDoc, true );
3972 if ( aSection.isNull() )
3975 // create filter item
3976 Filter_var aFilter = myFilterMgr->CreateFilter();
3978 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
3979 if ( aFilterItem.isNull() )
3983 aSection.appendChild( aFilterItem );
3984 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
3989 //=======================================================================
3990 // name : FilterLibrary_i::Delete
3991 // Purpose : Delete filter from library
3992 //=======================================================================
3993 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
3995 LDOM_Node aParentNode;
3996 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
3997 if ( aFilterNode.isNull() || aParentNode.isNull() )
4000 aParentNode.removeChild( aFilterNode );
4001 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
4005 //=======================================================================
4006 // name : FilterLibrary_i::Replace
4007 // Purpose : Replace existing filter with entry filter.
4008 // IMPORTANT : If filter does not exist it is not created
4009 //=======================================================================
4010 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
4011 const char* theNewName,
4012 Filter_ptr theFilter )
4014 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
4015 if ( aFilterItem.isNull() || theFilter->_is_nil() )
4018 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
4019 if ( aNewItem.isNull() )
4023 aFilterItem.ReplaceElement( aNewItem );
4024 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
4025 TPythonDump()<<this<<".Replace('"<<theFilterName<<"','"<<theNewName<<"',"<<aFilter<<")";
4030 //=======================================================================
4031 // name : FilterLibrary_i::Save
4032 // Purpose : Save library on disk
4033 //=======================================================================
4034 CORBA::Boolean FilterLibrary_i::Save()
4036 if ( myFileName == 0 || strlen( myFileName ) == 0 )
4040 fb.open( myFileName, std::ios::out );
4042 Standard_OStream os( &fb );
4044 LDOM_XmlWriter aWriter;
4045 aWriter.SetIndentation( 2 );
4046 aWriter.Write( os, myDoc );
4049 TPythonDump()<<this<<".Save()";
4053 //=======================================================================
4054 // name : FilterLibrary_i::SaveAs
4055 // Purpose : Save library on disk
4056 //=======================================================================
4057 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
4059 myFileName = strdup ( aFileName );
4060 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
4064 //=======================================================================
4065 // name : FilterLibrary_i::IsPresent
4066 // Purpose : Verify whether filter is in library
4067 //=======================================================================
4068 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
4070 return !findFilter( theFilterName, myDoc ).isNull();
4073 //=======================================================================
4074 // name : FilterLibrary_i::NbFilters
4075 // Purpose : Return amount of filters in library
4076 //=======================================================================
4077 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
4079 string_array_var aNames = GetNames( theType );
4080 return aNames->length();
4083 //=======================================================================
4084 // name : FilterLibrary_i::GetNames
4085 // Purpose : Get names of filters from library
4086 //=======================================================================
4087 string_array* FilterLibrary_i::GetNames( ElementType theType )
4089 string_array_var anArray = new string_array;
4090 TColStd_SequenceOfHAsciiString aSeq;
4092 LDOM_Node aSection = getSection( theType, myDoc, false );
4094 if ( !aSection.isNull() )
4096 for ( LDOM_Node aFilter = aSection.getFirstChild();
4097 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
4099 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
4100 aSeq.Append( new TCollection_HAsciiString(
4101 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
4105 anArray->length( aSeq.Length() );
4106 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
4107 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
4109 return anArray._retn();
4112 //=======================================================================
4113 // name : FilterLibrary_i::GetAllNames
4114 // Purpose : Get names of filters from library
4115 //=======================================================================
4116 string_array* FilterLibrary_i::GetAllNames()
4118 string_array_var aResArray = new string_array;
4119 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
4121 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
4123 int aPrevLength = aResArray->length();
4124 aResArray->length( aPrevLength + aNames->length() );
4125 for ( int i = 0, n = aNames->length(); i < n; i++ )
4126 aResArray[ aPrevLength + i ] = aNames[ i ];
4129 return aResArray._retn();
4132 //================================================================================
4134 * \brief Return an array of strings corresponding to items of enum FunctorType
4136 //================================================================================
4138 static const char** getFunctNames()
4140 static const char* functName[] = {
4141 // IT's necessary to update this array according to enum FunctorType (SMESH_Filter.idl)
4142 // The order is IMPORTANT !!!
4151 "FT_MaxElementLength2D",
4152 "FT_MaxElementLength3D",
4161 "FT_MultiConnection",
4162 "FT_MultiConnection2D",
4167 "FT_NodeConnectivityNumber",
4168 "FT_BelongToMeshGroup",
4171 "FT_BelongToCylinder",
4172 "FT_BelongToGenSurface",
4175 "FT_BadOrientedVolume",
4176 "FT_BareBorderVolume",
4177 "FT_BareBorderFace",
4178 "FT_OverConstrainedVolume",
4179 "FT_OverConstrainedFace",
4180 "FT_LinearOrQuadratic",
4186 "FT_ConnectedElements",
4196 // check if functName is complete, compilation failure means that enum FunctorType changed
4197 const int nbFunctors = sizeof(functName) / sizeof(const char*);
4198 int _assert[( nbFunctors == SMESH::FT_Undefined + 1 ) ? 2 : -1 ]; _assert[0]=_assert[1]=0;
4204 //================================================================================
4206 * \brief Return a string corresponding to an item of enum FunctorType
4208 //================================================================================
4210 const char* SMESH::FunctorTypeToString(SMESH::FunctorType ft)
4212 if ( ft < 0 || ft > SMESH::FT_Undefined )
4213 return "FT_Undefined";
4214 return getFunctNames()[ ft ];
4217 //================================================================================
4219 * \brief Converts a string to FunctorType. This is reverse of FunctorTypeToString()
4221 //================================================================================
4223 SMESH::FunctorType SMESH::StringToFunctorType(const char* str)
4225 std::string name( str + 3 ); // skip "FT_"
4226 const char** functNames = getFunctNames();
4228 for ( ; ft < SMESH::FT_Undefined; ++ft )
4229 if ( name == ( functNames[ft] + 3 ))
4232 //ASSERT( strcmp( str, FunctorTypeToString( SMESH::FunctorType( ft ))) == 0 );
4234 return SMESH::FunctorType( ft );
4237 //================================================================================
4239 * \brief calls OnBaseObjModified(), if who != this, and myWaiters[i]->Modified(who)
4241 //================================================================================
4243 void NotifyerAndWaiter::Modified( bool removed, NotifyerAndWaiter* who )
4245 if ( who != 0 && who != this )
4246 OnBaseObjModified( who, removed );
4250 std::list<NotifyerAndWaiter*> waiters = myWaiters; // myWaiters can be changed by Modified()
4251 std::list<NotifyerAndWaiter*>::iterator i = waiters.begin();
4252 for ( ; i != waiters.end(); ++i )
4253 (*i)->Modified( removed, who );
4256 //================================================================================
4258 * \brief Stores an object to be notified on change of predicate
4260 //================================================================================
4262 void NotifyerAndWaiter::AddModifWaiter( NotifyerAndWaiter* waiter )
4265 myWaiters.push_back( waiter );
4268 //================================================================================
4270 * \brief Removes an object to be notified on change of predicate
4272 //================================================================================
4274 void NotifyerAndWaiter::RemoveModifWaiter( NotifyerAndWaiter* waiter )
4276 myWaiters.remove( waiter );
4279 //================================================================================
4281 * \brief Checks if a waiter is among myWaiters, maybe nested
4283 //================================================================================
4285 bool NotifyerAndWaiter::ContainModifWaiter( NotifyerAndWaiter* waiter )
4287 bool is = ( waiter == this );
4289 std::list<NotifyerAndWaiter*>::iterator w = myWaiters.begin();
4290 for ( ; !is && w != myWaiters.end(); ++w )
4291 is = (*w)->ContainModifWaiter( waiter );