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 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
907 myBelongToGeomPtr->SetGeom( aLocShape );
908 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
911 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
913 myBelongToGeomPtr->SetGeom( theShape );
916 void BelongToGeom_i::SetElementType(ElementType theType)
918 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
919 TPythonDump()<<this<<".SetElementType("<<theType<<")";
922 FunctorType BelongToGeom_i::GetFunctorType()
924 return SMESH::FT_BelongToGeom;
927 void BelongToGeom_i::SetShapeName( const char* theName )
929 CORBA::string_free( myShapeName );
930 myShapeName = CORBA::string_dup( theName );
931 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
932 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
935 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
937 CORBA::string_free( myShapeName );
938 CORBA::string_free( myShapeID );
939 myShapeName = CORBA::string_dup( theName );
940 myShapeID = CORBA::string_dup( theID );
941 bool hasName = ( theName && theName[0] );
942 bool hasID = ( theID && theID[0] );
945 if ( hasName && hasID )
947 S = getShapeByID( myShapeID );
949 S = getShapeByName( myShapeName );
953 S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
955 myBelongToGeomPtr->SetGeom( S );
958 char* BelongToGeom_i::GetShapeName()
960 return CORBA::string_dup( myShapeName );
963 char* BelongToGeom_i::GetShapeID()
965 return CORBA::string_dup( myShapeID );
968 void BelongToGeom_i::SetTolerance( CORBA::Double theToler )
970 myBelongToGeomPtr->SetTolerance( theToler );
971 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
974 CORBA::Double BelongToGeom_i::GetTolerance()
976 return myBelongToGeomPtr->GetTolerance();
980 Class : BelongToSurface_i
981 Description : Predicate for selection on geometrical support
983 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
985 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
986 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
989 mySurfaceType = theSurfaceType;
992 BelongToSurface_i::~BelongToSurface_i()
994 CORBA::string_free( myShapeName );
995 CORBA::string_free( myShapeID );
998 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1000 if ( theGeom->_is_nil() )
1002 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1004 if ( aLocShape.ShapeType() == TopAbs_FACE )
1006 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
1007 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
1009 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1014 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
1017 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
1019 CORBA::string_free( myShapeName );
1020 myShapeName = CORBA::string_dup( theName );
1021 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1022 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
1025 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
1027 CORBA::string_free( myShapeName );
1028 CORBA::string_free( myShapeID );
1029 myShapeName = CORBA::string_dup( theName );
1030 myShapeID = CORBA::string_dup( theID );
1031 bool hasName = ( theName && theName[0] );
1032 bool hasID = ( theID && theID[0] );
1035 if ( hasName && hasID )
1037 S = getShapeByID( myShapeID );
1039 S = getShapeByName( myShapeName );
1043 S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
1045 myElementsOnSurfacePtr->SetSurface( S, (SMDSAbs_ElementType)theType );
1048 char* BelongToSurface_i::GetShapeName()
1050 return CORBA::string_dup( myShapeName );
1053 char* BelongToSurface_i::GetShapeID()
1055 return CORBA::string_dup( myShapeID );
1058 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
1060 myElementsOnSurfacePtr->SetTolerance( theToler );
1061 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1064 CORBA::Double BelongToSurface_i::GetTolerance()
1066 return myElementsOnSurfacePtr->GetTolerance();
1069 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
1071 myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
1072 TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
1075 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
1077 return myElementsOnSurfacePtr->GetUseBoundaries();
1082 Class : BelongToPlane_i
1083 Description : Verify whether mesh element lie in pointed Geom planar object
1086 BelongToPlane_i::BelongToPlane_i()
1087 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
1091 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1093 BelongToSurface_i::SetSurface( theGeom, theType );
1094 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
1097 FunctorType BelongToPlane_i::GetFunctorType()
1099 return FT_BelongToPlane;
1103 Class : BelongToCylinder_i
1104 Description : Verify whether mesh element lie in pointed Geom planar object
1107 BelongToCylinder_i::BelongToCylinder_i()
1108 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1112 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1114 BelongToSurface_i::SetSurface( theGeom, theType );
1115 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
1118 FunctorType BelongToCylinder_i::GetFunctorType()
1120 return FT_BelongToCylinder;
1124 Class : BelongToGenSurface_i
1125 Description : Verify whether mesh element lie in pointed Geom planar object
1128 BelongToGenSurface_i::BelongToGenSurface_i()
1129 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1133 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1135 if ( theGeom->_is_nil() )
1137 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1138 if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1139 aLocShape.Nullify();
1141 BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1142 TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1145 FunctorType BelongToGenSurface_i::GetFunctorType()
1147 return FT_BelongToGenSurface;
1151 Class : LyingOnGeom_i
1152 Description : Predicate for selection on geometrical support
1154 LyingOnGeom_i::LyingOnGeom_i()
1156 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1157 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1162 LyingOnGeom_i::~LyingOnGeom_i()
1164 CORBA::string_free( myShapeName );
1165 CORBA::string_free( myShapeID );
1168 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1170 if ( theGeom->_is_nil() )
1172 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1173 myLyingOnGeomPtr->SetGeom( aLocShape );
1174 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1177 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1179 myLyingOnGeomPtr->SetGeom( theShape );
1182 void LyingOnGeom_i::SetElementType(ElementType theType){
1183 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1184 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1187 FunctorType LyingOnGeom_i::GetFunctorType()
1189 return SMESH::FT_LyingOnGeom;
1192 void LyingOnGeom_i::SetShapeName( const char* theName )
1194 CORBA::string_free( myShapeName );
1195 myShapeName = CORBA::string_dup( theName );
1196 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1197 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1200 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1202 CORBA::string_free( myShapeName );
1203 CORBA::string_free( myShapeID );
1204 myShapeName = CORBA::string_dup( theName );
1205 myShapeID = CORBA::string_dup( theID );
1206 bool hasName = ( theName && theName[0] );
1207 bool hasID = ( theID && theID[0] );
1210 if ( hasName && hasID )
1212 S = getShapeByID( myShapeID );
1214 S = getShapeByName( myShapeName );
1218 S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
1220 myLyingOnGeomPtr->SetGeom( S );
1223 char* LyingOnGeom_i::GetShapeName()
1225 return CORBA::string_dup( myShapeName );
1228 char* LyingOnGeom_i::GetShapeID()
1230 return CORBA::string_dup( myShapeID );
1233 void LyingOnGeom_i::SetTolerance( CORBA::Double theToler )
1235 myLyingOnGeomPtr->SetTolerance( theToler );
1236 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1239 CORBA::Double LyingOnGeom_i::GetTolerance()
1241 return myLyingOnGeomPtr->GetTolerance();
1245 Class : FreeBorders_i
1246 Description : Predicate for free borders
1248 FreeBorders_i::FreeBorders_i()
1250 myPredicatePtr.reset(new Controls::FreeBorders());
1251 myFunctorPtr = myPredicatePtr;
1254 FunctorType FreeBorders_i::GetFunctorType()
1256 return SMESH::FT_FreeBorders;
1261 Description : Predicate for free borders
1263 FreeEdges_i::FreeEdges_i()
1264 : myFreeEdgesPtr( new Controls::FreeEdges() )
1266 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1269 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1271 SMESH::Controls::FreeEdges::TBorders aBorders;
1272 myFreeEdgesPtr->GetBoreders( aBorders );
1274 long i = 0, iEnd = aBorders.size();
1276 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1277 aResult->length(iEnd);
1279 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1280 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1282 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1283 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1285 aBorder.myElemId = aBord.myElemId;
1286 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1287 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1289 return aResult._retn();
1292 FunctorType FreeEdges_i::GetFunctorType()
1294 return SMESH::FT_FreeEdges;
1299 Description : Predicate for free faces
1301 FreeFaces_i::FreeFaces_i()
1303 myPredicatePtr.reset(new Controls::FreeFaces());
1304 myFunctorPtr = myPredicatePtr;
1307 FunctorType FreeFaces_i::GetFunctorType()
1309 return SMESH::FT_FreeFaces;
1314 Description : Predicate for free nodes
1316 FreeNodes_i::FreeNodes_i()
1318 myPredicatePtr.reset(new Controls::FreeNodes());
1319 myFunctorPtr = myPredicatePtr;
1322 FunctorType FreeNodes_i::GetFunctorType()
1324 return SMESH::FT_FreeNodes;
1328 Class : EqualNodes_i
1329 Description : Predicate for Equal nodes
1331 EqualNodes_i::EqualNodes_i()
1333 myCoincidentNodesPtr.reset(new Controls::CoincidentNodes());
1334 myFunctorPtr = myPredicatePtr = myCoincidentNodesPtr;
1337 FunctorType EqualNodes_i::GetFunctorType()
1339 return SMESH::FT_EqualNodes;
1342 void EqualNodes_i::SetTolerance( double tol )
1344 myCoincidentNodesPtr->SetTolerance( tol );
1347 double EqualNodes_i::GetTolerance()
1349 return myCoincidentNodesPtr->GetTolerance();
1353 Class : EqualEdges_i
1354 Description : Predicate for Equal Edges
1356 EqualEdges_i::EqualEdges_i()
1358 myPredicatePtr.reset(new Controls::CoincidentElements1D());
1359 myFunctorPtr = myPredicatePtr;
1362 FunctorType EqualEdges_i::GetFunctorType()
1364 return SMESH::FT_EqualEdges;
1368 Class : EqualFaces_i
1369 Description : Predicate for Equal Faces
1371 EqualFaces_i::EqualFaces_i()
1373 myPredicatePtr.reset(new Controls::CoincidentElements2D());
1374 myFunctorPtr = myPredicatePtr;
1377 FunctorType EqualFaces_i::GetFunctorType()
1379 return SMESH::FT_EqualFaces;
1383 Class : EqualVolumes_i
1384 Description : Predicate for Equal Volumes
1386 EqualVolumes_i::EqualVolumes_i()
1388 myPredicatePtr.reset(new Controls::CoincidentElements3D());
1389 myFunctorPtr = myPredicatePtr;
1392 FunctorType EqualVolumes_i::GetFunctorType()
1394 return SMESH::FT_EqualVolumes;
1399 Class : RangeOfIds_i
1400 Description : Predicate for Range of Ids.
1401 Range may be specified with two ways.
1402 1. Using AddToRange method
1403 2. With SetRangeStr method. Parameter of this method is a string
1404 like as "1,2,3,50-60,63,67,70-"
1407 RangeOfIds_i::RangeOfIds_i()
1409 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1410 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1413 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1415 CORBA::Long iEnd = theIds.length();
1416 for ( CORBA::Long i = 0; i < iEnd; i++ )
1417 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1418 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1421 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1423 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1424 return myRangeOfIdsPtr->SetRangeStr(
1425 TCollection_AsciiString( (Standard_CString)theRange ) );
1428 char* RangeOfIds_i::GetRangeStr()
1430 TCollection_AsciiString aStr;
1431 myRangeOfIdsPtr->GetRangeStr( aStr );
1432 return CORBA::string_dup( aStr.ToCString() );
1435 void RangeOfIds_i::SetElementType( ElementType theType )
1437 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1438 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1441 FunctorType RangeOfIds_i::GetFunctorType()
1443 return SMESH::FT_RangeOfIds;
1447 Class : LinearOrQuadratic_i
1448 Description : Predicate to verify whether a mesh element is linear
1450 LinearOrQuadratic_i::LinearOrQuadratic_i()
1452 myLinearOrQuadraticPtr.reset(new Controls::LinearOrQuadratic());
1453 myFunctorPtr = myPredicatePtr = myLinearOrQuadraticPtr;
1456 void LinearOrQuadratic_i::SetElementType(ElementType theType)
1458 myLinearOrQuadraticPtr->SetType(SMDSAbs_ElementType(theType));
1459 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1462 FunctorType LinearOrQuadratic_i::GetFunctorType()
1464 return SMESH::FT_LinearOrQuadratic;
1468 Class : GroupColor_i
1469 Description : Functor for check color of group to which mesh element belongs to
1471 GroupColor_i::GroupColor_i()
1473 myGroupColorPtr.reset(new Controls::GroupColor());
1474 myFunctorPtr = myPredicatePtr = myGroupColorPtr;
1477 FunctorType GroupColor_i::GetFunctorType()
1479 return SMESH::FT_GroupColor;
1482 void GroupColor_i::SetColorStr( const char* theColor )
1484 myGroupColorPtr->SetColorStr(
1485 TCollection_AsciiString( (Standard_CString)theColor ) );
1486 TPythonDump()<<this<<".SetColorStr('"<<theColor<<"')";
1489 char* GroupColor_i::GetColorStr()
1491 TCollection_AsciiString aStr;
1492 myGroupColorPtr->GetColorStr( aStr );
1493 return CORBA::string_dup( aStr.ToCString() );
1496 void GroupColor_i::SetElementType(ElementType theType)
1498 myGroupColorPtr->SetType(SMDSAbs_ElementType(theType));
1499 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1503 Class : ElemGeomType_i
1504 Description : Predicate check is element has indicated geometry type
1506 ElemGeomType_i::ElemGeomType_i()
1508 myElemGeomTypePtr.reset(new Controls::ElemGeomType());
1509 myFunctorPtr = myPredicatePtr = myElemGeomTypePtr;
1512 void ElemGeomType_i::SetElementType(ElementType theType)
1514 myElemGeomTypePtr->SetType(SMDSAbs_ElementType(theType));
1515 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1518 void ElemGeomType_i::SetGeometryType(GeometryType theType)
1520 myElemGeomTypePtr->SetGeomType(SMDSAbs_GeometryType(theType));
1521 TPythonDump()<<this<<".SetGeometryType("<<theType<<")";
1524 GeometryType ElemGeomType_i::GetGeometryType() const
1526 return (GeometryType)myElemGeomTypePtr->GetGeomType();
1529 FunctorType ElemGeomType_i::GetFunctorType()
1531 return SMESH::FT_ElemGeomType;
1535 Class : ElemEntityType_i
1536 Description : Predicate check is element has indicated entity type
1538 ElemEntityType_i::ElemEntityType_i()
1540 myElemEntityTypePtr.reset(new Controls::ElemEntityType());
1541 myFunctorPtr = myPredicatePtr = myElemEntityTypePtr;
1544 void ElemEntityType_i::SetElementType(ElementType theType)
1546 myElemEntityTypePtr->SetType(SMDSAbs_ElementType(theType));
1547 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1550 void ElemEntityType_i::SetEntityType(EntityType theEntityType)
1552 myElemEntityTypePtr->SetElemEntityType(SMDSAbs_EntityType (theEntityType));
1553 TPythonDump()<<this<<".SetEntityType("<<theEntityType<<")";
1555 EntityType ElemEntityType_i::GetEntityType() const
1557 return (EntityType) myElemEntityTypePtr->GetElemEntityType();
1560 FunctorType ElemEntityType_i::GetFunctorType()
1562 return SMESH::FT_EntityType;
1566 Class : CoplanarFaces_i
1567 Description : Returns true if a mesh face is a coplanar neighbour to a given one
1569 CoplanarFaces_i::CoplanarFaces_i()
1571 myCoplanarFacesPtr.reset(new Controls::CoplanarFaces());
1572 myFunctorPtr = myPredicatePtr = myCoplanarFacesPtr;
1575 void CoplanarFaces_i::SetFace ( CORBA::Long theFaceID )
1577 myCoplanarFacesPtr->SetFace(theFaceID);
1578 TPythonDump()<<this<<".SetFace("<<theFaceID<<")";
1581 void CoplanarFaces_i::SetTolerance( CORBA::Double theToler )
1583 myCoplanarFacesPtr->SetTolerance(theToler);
1584 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1587 CORBA::Long CoplanarFaces_i::GetFace () const
1589 return myCoplanarFacesPtr->GetFace();
1592 char* CoplanarFaces_i::GetFaceAsString () const
1594 TCollection_AsciiString str(Standard_Integer(myCoplanarFacesPtr->GetFace()));
1595 return CORBA::string_dup( str.ToCString() );
1598 CORBA::Double CoplanarFaces_i::GetTolerance() const
1600 return myCoplanarFacesPtr->GetTolerance();
1603 FunctorType CoplanarFaces_i::GetFunctorType()
1605 return SMESH::FT_CoplanarFaces;
1609 * Class : ConnectedElements_i
1610 * Description : Returns true if an element is connected via other elements to the element
1611 * located at a given point.
1613 ConnectedElements_i::ConnectedElements_i()
1615 myConnectedElementsPtr.reset(new Controls::ConnectedElements());
1616 myFunctorPtr = myPredicatePtr = myConnectedElementsPtr;
1619 FunctorType ConnectedElements_i::GetFunctorType()
1621 return FT_ConnectedElements;
1624 void ConnectedElements_i::SetElementType( ElementType theType )
1626 myConnectedElementsPtr->SetType( SMDSAbs_ElementType( theType ));
1627 TPythonDump() << this << ".SetElementType( " << theType << " )";
1630 void ConnectedElements_i::SetPoint( CORBA::Double x, CORBA::Double y, CORBA::Double z )
1632 myConnectedElementsPtr->SetPoint( x,y,z );
1634 TPythonDump() << this << ".SetPoint( " << x << ", " << y << ", " << z << " )";
1637 void ConnectedElements_i::SetVertex( GEOM::GEOM_Object_ptr vertex )
1638 throw (SALOME::SALOME_Exception)
1640 TopoDS_Shape shape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( vertex );
1641 if ( shape.IsNull() )
1642 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetVertex(): NULL Vertex",
1643 SALOME::BAD_PARAM );
1645 TopExp_Explorer v( shape, TopAbs_VERTEX );
1647 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetVertex(): empty vertex",
1648 SALOME::BAD_PARAM );
1650 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( v.Current() ));
1651 myConnectedElementsPtr->SetPoint( p.X(), p.Y(), p.Z() );
1653 CORBA::String_var id = vertex->GetStudyEntry();
1654 myVertexID = id.in();
1656 TPythonDump() << this << ".SetVertex( " << vertex << " )";
1659 void ConnectedElements_i::SetNode ( CORBA::Long nodeID )
1660 throw (SALOME::SALOME_Exception)
1663 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetNode(): nodeID must be > 0",
1664 SALOME::BAD_PARAM );
1666 myConnectedElementsPtr->SetNode( nodeID );
1668 TPythonDump() << this << ".SetNode( " << nodeID << " )";
1672 * \brief This is a comfort method for Filter dialog
1674 void ConnectedElements_i::SetThreshold ( const char* threshold,
1675 SMESH::ConnectedElements::ThresholdType type )
1676 throw (SALOME::SALOME_Exception)
1679 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetThreshold(): NULL threshold",
1680 SALOME::BAD_PARAM );
1683 case SMESH::ConnectedElements::POINT: // read 3 node coordinates ///////////////////
1685 std::vector< double > xyz;
1690 while ( *threshold &&
1691 *threshold != '+' &&
1692 *threshold != '-' &&
1693 !isdigit( *threshold ))
1697 // read a coordinate
1698 xyz.push_back( strtod( threshold, &endptr ));
1699 if ( threshold == endptr )
1701 xyz.resize( xyz.size() - 1 );
1706 while ( xyz.size() < 3 );
1708 if ( xyz.size() < 3 )
1709 THROW_SALOME_CORBA_EXCEPTION
1710 ( "ConnectedElements_i::SetThreshold(): invalid point coordinates", SALOME::BAD_PARAM );
1712 SetPoint( xyz[0], xyz[1], xyz[2] );
1715 case SMESH::ConnectedElements::VERTEX: // get a VERTEX by its entry /////////////////
1717 SALOMEDS::SObject_wrap sobj = SMESH_Gen_i::getStudyServant()->FindObjectID( threshold );
1718 if ( sobj->_is_nil() )
1719 THROW_SALOME_CORBA_EXCEPTION
1720 ( "ConnectedElements_i::SetThreshold(): invalid vertex study entry", SALOME::BAD_PARAM );
1721 CORBA::Object_var obj = sobj->GetObject();
1722 GEOM::GEOM_Object_var vertex = GEOM::GEOM_Object::_narrow( obj );
1723 if ( vertex->_is_nil() )
1724 THROW_SALOME_CORBA_EXCEPTION
1725 ( "ConnectedElements_i::SetThreshold(): no GEOM_Object in SObject", SALOME::BAD_PARAM );
1726 SetVertex( vertex );
1729 case SMESH::ConnectedElements::NODE: // read a node ID ////////////////////////////
1732 int id = strtol( threshold, &endptr, 10 );
1733 if ( threshold == endptr )
1734 THROW_SALOME_CORBA_EXCEPTION
1735 ( "ConnectedElements_i::SetThreshold(): invalid node ID", SALOME::BAD_PARAM );
1740 THROW_SALOME_CORBA_EXCEPTION
1741 ( "ConnectedElements_i::SetThreshold(): invalid ThresholdType", SALOME::BAD_PARAM );
1745 char* ConnectedElements_i::GetThreshold ( SMESH::ConnectedElements::ThresholdType& type )
1747 std::string threshold;
1748 if ( !myVertexID.empty() )
1750 threshold = myVertexID;
1751 type = SMESH::ConnectedElements::VERTEX;
1755 std::vector<double> xyz = myConnectedElementsPtr->GetPoint();
1756 if ( xyz.size() == 3 )
1758 threshold = SMESH_Comment( xyz[0] ) << "; " << xyz[1] << "; " << xyz[2];
1759 type = SMESH::ConnectedElements::POINT;
1763 threshold = SMESH_Comment( myConnectedElementsPtr->GetNode() );
1764 type = SMESH::ConnectedElements::NODE;
1767 return CORBA::string_dup( threshold.c_str() );
1771 Class : Comparator_i
1772 Description : Base class for comparators
1774 Comparator_i::Comparator_i():
1775 myNumericalFunctor( NULL )
1778 Comparator_i::~Comparator_i()
1780 if ( myNumericalFunctor )
1781 myNumericalFunctor->UnRegister();
1784 void Comparator_i::SetMargin( CORBA::Double theValue )
1786 myComparatorPtr->SetMargin( theValue );
1787 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1790 CORBA::Double Comparator_i::GetMargin()
1792 return myComparatorPtr->GetMargin();
1795 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1797 if ( myNumericalFunctor )
1798 myNumericalFunctor->UnRegister();
1800 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1802 if ( myNumericalFunctor )
1804 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1805 myNumericalFunctor->Register();
1806 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1810 Controls::ComparatorPtr Comparator_i::GetComparator()
1812 return myComparatorPtr;
1815 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1817 return myNumericalFunctor;
1823 Description : Comparator "<"
1825 LessThan_i::LessThan_i()
1827 myComparatorPtr.reset( new Controls::LessThan() );
1828 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1831 FunctorType LessThan_i::GetFunctorType()
1833 return SMESH::FT_LessThan;
1839 Description : Comparator ">"
1841 MoreThan_i::MoreThan_i()
1843 myComparatorPtr.reset( new Controls::MoreThan() );
1844 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1847 FunctorType MoreThan_i::GetFunctorType()
1849 return SMESH::FT_MoreThan;
1855 Description : Comparator "="
1857 EqualTo_i::EqualTo_i()
1858 : myEqualToPtr( new Controls::EqualTo() )
1860 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1863 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1865 myEqualToPtr->SetTolerance( theToler );
1866 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1869 CORBA::Double EqualTo_i::GetTolerance()
1871 return myEqualToPtr->GetTolerance();
1874 FunctorType EqualTo_i::GetFunctorType()
1876 return SMESH::FT_EqualTo;
1880 Class : LogicalNOT_i
1881 Description : Logical NOT predicate
1883 LogicalNOT_i::LogicalNOT_i():
1884 myLogicalNOTPtr( new Controls::LogicalNOT() ),
1887 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1890 LogicalNOT_i::~LogicalNOT_i()
1893 myPredicate->UnRegister();
1896 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1899 myPredicate->UnRegister();
1901 myPredicate = SMESH::GetPredicate(thePredicate);
1904 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1905 myPredicate->Register();
1906 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1910 FunctorType LogicalNOT_i::GetFunctorType()
1912 return SMESH::FT_LogicalNOT;
1915 Predicate_i* LogicalNOT_i::GetPredicate_i()
1923 Class : LogicalBinary_i
1924 Description : Base class for binary logical predicate
1926 LogicalBinary_i::LogicalBinary_i()
1927 : myPredicate1( NULL ),
1928 myPredicate2( NULL )
1931 LogicalBinary_i::~LogicalBinary_i()
1934 myPredicate1->UnRegister();
1937 myPredicate2->UnRegister();
1940 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1943 myPredicate1->SetMesh( theMesh );
1946 myPredicate2->SetMesh( theMesh );
1949 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1952 myPredicate1->UnRegister();
1954 myPredicate1 = SMESH::GetPredicate(thePredicate);
1956 if ( myPredicate1 ){
1957 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1958 myPredicate1->Register();
1959 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1963 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1966 myPredicate2->UnRegister();
1968 myPredicate2 = SMESH::GetPredicate(thePredicate);
1970 if ( myPredicate2 ){
1971 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1972 myPredicate2->Register();
1973 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1977 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1979 return myLogicalBinaryPtr;
1982 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1984 return myPredicate1;
1986 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1988 return myPredicate2;
1993 Class : LogicalAND_i
1994 Description : Logical AND
1996 LogicalAND_i::LogicalAND_i()
1998 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1999 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
2002 FunctorType LogicalAND_i::GetFunctorType()
2004 return SMESH::FT_LogicalAND;
2010 Description : Logical OR
2012 LogicalOR_i::LogicalOR_i()
2014 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
2015 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
2018 FunctorType LogicalOR_i::GetFunctorType()
2020 return SMESH::FT_LogicalOR;
2028 FilterManager_i::FilterManager_i()
2029 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
2031 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
2032 //PortableServer::ObjectId_var anObjectId =
2033 // SMESH_Gen_i::GetPOA()->activate_object( this );
2037 FilterManager_i::~FilterManager_i()
2039 //TPythonDump()<<this<<".UnRegister()";
2043 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
2045 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
2046 SMESH::MinimumAngle_var anObj = aServant->_this();
2047 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
2048 return anObj._retn();
2052 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
2054 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
2055 SMESH::AspectRatio_var anObj = aServant->_this();
2056 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
2057 return anObj._retn();
2061 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
2063 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
2064 SMESH::AspectRatio3D_var anObj = aServant->_this();
2065 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
2066 return anObj._retn();
2070 Warping_ptr FilterManager_i::CreateWarping()
2072 SMESH::Warping_i* aServant = new SMESH::Warping_i();
2073 SMESH::Warping_var anObj = aServant->_this();
2074 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
2075 return anObj._retn();
2079 Taper_ptr FilterManager_i::CreateTaper()
2081 SMESH::Taper_i* aServant = new SMESH::Taper_i();
2082 SMESH::Taper_var anObj = aServant->_this();
2083 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
2084 return anObj._retn();
2088 Skew_ptr FilterManager_i::CreateSkew()
2090 SMESH::Skew_i* aServant = new SMESH::Skew_i();
2091 SMESH::Skew_var anObj = aServant->_this();
2092 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
2093 return anObj._retn();
2097 Area_ptr FilterManager_i::CreateArea()
2099 SMESH::Area_i* aServant = new SMESH::Area_i();
2100 SMESH::Area_var anObj = aServant->_this();
2101 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
2102 return anObj._retn();
2106 Volume3D_ptr FilterManager_i::CreateVolume3D()
2108 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
2109 SMESH::Volume3D_var anObj = aServant->_this();
2110 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
2111 return anObj._retn();
2115 MaxElementLength2D_ptr FilterManager_i::CreateMaxElementLength2D()
2117 SMESH::MaxElementLength2D_i* aServant = new SMESH::MaxElementLength2D_i();
2118 SMESH::MaxElementLength2D_var anObj = aServant->_this();
2119 TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength2D()";
2120 return anObj._retn();
2124 MaxElementLength3D_ptr FilterManager_i::CreateMaxElementLength3D()
2126 SMESH::MaxElementLength3D_i* aServant = new SMESH::MaxElementLength3D_i();
2127 SMESH::MaxElementLength3D_var anObj = aServant->_this();
2128 TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength3D()";
2129 return anObj._retn();
2133 Length_ptr FilterManager_i::CreateLength()
2135 SMESH::Length_i* aServant = new SMESH::Length_i();
2136 SMESH::Length_var anObj = aServant->_this();
2137 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
2138 return anObj._retn();
2141 Length2D_ptr FilterManager_i::CreateLength2D()
2143 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
2144 SMESH::Length2D_var anObj = aServant->_this();
2145 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
2146 return anObj._retn();
2149 Length3D_ptr FilterManager_i::CreateLength3D()
2151 SMESH::Length3D_i* aServant = new SMESH::Length3D_i();
2152 SMESH::Length3D_var anObj = aServant->_this();
2153 TPythonDump()<<aServant<<" = "<<this<<".CreateLength3D()";
2154 return anObj._retn();
2157 Deflection2D_ptr FilterManager_i::CreateDeflection2D()
2159 SMESH::Deflection2D_i* aServant = new SMESH::Deflection2D_i();
2160 SMESH::Deflection2D_var anObj = aServant->_this();
2161 TPythonDump()<<aServant<<" = "<<this<<".CreateDeflection2D()";
2162 return anObj._retn();
2165 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
2167 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
2168 SMESH::MultiConnection_var anObj = aServant->_this();
2169 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
2170 return anObj._retn();
2173 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
2175 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
2176 SMESH::MultiConnection2D_var anObj = aServant->_this();
2177 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
2178 return anObj._retn();
2181 BallDiameter_ptr FilterManager_i::CreateBallDiameter()
2183 SMESH::BallDiameter_i* aServant = new SMESH::BallDiameter_i();
2184 SMESH::BallDiameter_var anObj = aServant->_this();
2185 TPythonDump()<<aServant<<" = "<<this<<".CreateBallDiameter()";
2186 return anObj._retn();
2189 NodeConnectivityNumber_ptr FilterManager_i::CreateNodeConnectivityNumber()
2191 SMESH::NodeConnectivityNumber_i* aServant = new SMESH::NodeConnectivityNumber_i();
2192 SMESH::NodeConnectivityNumber_var anObj = aServant->_this();
2193 TPythonDump()<<aServant<<" = "<<this<<".CreateNodeConnectivityNumber()";
2194 return anObj._retn();
2197 BelongToMeshGroup_ptr FilterManager_i::CreateBelongToMeshGroup()
2199 SMESH::BelongToMeshGroup_i* aServant = new SMESH::BelongToMeshGroup_i();
2200 SMESH::BelongToMeshGroup_var anObj = aServant->_this();
2201 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToMeshGroup()";
2202 return anObj._retn();
2205 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
2207 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
2208 SMESH::BelongToGeom_var anObj = aServant->_this();
2209 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
2210 return anObj._retn();
2213 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
2215 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
2216 SMESH::BelongToPlane_var anObj = aServant->_this();
2217 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
2218 return anObj._retn();
2221 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
2223 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
2224 SMESH::BelongToCylinder_var anObj = aServant->_this();
2225 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
2226 return anObj._retn();
2229 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
2231 SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
2232 SMESH::BelongToGenSurface_var anObj = aServant->_this();
2233 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
2234 return anObj._retn();
2237 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
2239 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
2240 SMESH::LyingOnGeom_var anObj = aServant->_this();
2241 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
2242 return anObj._retn();
2245 CoplanarFaces_ptr FilterManager_i::CreateCoplanarFaces()
2247 SMESH::CoplanarFaces_i* aServant = new SMESH::CoplanarFaces_i();
2248 SMESH::CoplanarFaces_var anObj = aServant->_this();
2249 TPythonDump()<<aServant<<" = "<<this<<".CreateCoplanarFaces()";
2250 return anObj._retn();
2253 ConnectedElements_ptr FilterManager_i::CreateConnectedElements()
2255 SMESH::ConnectedElements_i* aServant = new SMESH::ConnectedElements_i();
2256 SMESH::ConnectedElements_var anObj = aServant->_this();
2257 TPythonDump()<<aServant<<" = "<<this<<".CreateConnectedElements()";
2258 return anObj._retn();
2261 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
2263 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
2264 SMESH::FreeBorders_var anObj = aServant->_this();
2265 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
2266 return anObj._retn();
2269 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
2271 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
2272 SMESH::FreeEdges_var anObj = aServant->_this();
2273 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
2274 return anObj._retn();
2277 FreeFaces_ptr FilterManager_i::CreateFreeFaces()
2279 SMESH::FreeFaces_i* aServant = new SMESH::FreeFaces_i();
2280 SMESH::FreeFaces_var anObj = aServant->_this();
2281 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeFaces()";
2282 return anObj._retn();
2285 FreeNodes_ptr FilterManager_i::CreateFreeNodes()
2287 SMESH::FreeNodes_i* aServant = new SMESH::FreeNodes_i();
2288 SMESH::FreeNodes_var anObj = aServant->_this();
2289 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeNodes()";
2290 return anObj._retn();
2293 EqualNodes_ptr FilterManager_i::CreateEqualNodes()
2295 SMESH::EqualNodes_i* aServant = new SMESH::EqualNodes_i();
2296 SMESH::EqualNodes_var anObj = aServant->_this();
2297 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualNodes()";
2298 return anObj._retn();
2301 EqualEdges_ptr FilterManager_i::CreateEqualEdges()
2303 SMESH::EqualEdges_i* aServant = new SMESH::EqualEdges_i();
2304 SMESH::EqualEdges_var anObj = aServant->_this();
2305 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualEdges()";
2306 return anObj._retn();
2308 EqualFaces_ptr FilterManager_i::CreateEqualFaces()
2310 SMESH::EqualFaces_i* aServant = new SMESH::EqualFaces_i();
2311 SMESH::EqualFaces_var anObj = aServant->_this();
2312 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualFaces()";
2313 return anObj._retn();
2315 EqualVolumes_ptr FilterManager_i::CreateEqualVolumes()
2317 SMESH::EqualVolumes_i* aServant = new SMESH::EqualVolumes_i();
2318 SMESH::EqualVolumes_var anObj = aServant->_this();
2319 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualVolumes()";
2320 return anObj._retn();
2323 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
2325 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
2326 SMESH::RangeOfIds_var anObj = aServant->_this();
2327 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
2328 return anObj._retn();
2331 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
2333 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
2334 SMESH::BadOrientedVolume_var anObj = aServant->_this();
2335 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
2336 return anObj._retn();
2339 BareBorderVolume_ptr FilterManager_i::CreateBareBorderVolume()
2341 SMESH::BareBorderVolume_i* aServant = new SMESH::BareBorderVolume_i();
2342 SMESH::BareBorderVolume_var anObj = aServant->_this();
2343 TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderVolume()";
2344 return anObj._retn();
2347 BareBorderFace_ptr FilterManager_i::CreateBareBorderFace()
2349 SMESH::BareBorderFace_i* aServant = new SMESH::BareBorderFace_i();
2350 SMESH::BareBorderFace_var anObj = aServant->_this();
2351 TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderFace()";
2352 return anObj._retn();
2355 OverConstrainedVolume_ptr FilterManager_i::CreateOverConstrainedVolume()
2357 SMESH::OverConstrainedVolume_i* aServant = new SMESH::OverConstrainedVolume_i();
2358 SMESH::OverConstrainedVolume_var anObj = aServant->_this();
2359 TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedVolume()";
2360 return anObj._retn();
2363 OverConstrainedFace_ptr FilterManager_i::CreateOverConstrainedFace()
2365 SMESH::OverConstrainedFace_i* aServant = new SMESH::OverConstrainedFace_i();
2366 SMESH::OverConstrainedFace_var anObj = aServant->_this();
2367 TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedFace()";
2368 return anObj._retn();
2371 LessThan_ptr FilterManager_i::CreateLessThan()
2373 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
2374 SMESH::LessThan_var anObj = aServant->_this();
2375 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
2376 return anObj._retn();
2379 MoreThan_ptr FilterManager_i::CreateMoreThan()
2381 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
2382 SMESH::MoreThan_var anObj = aServant->_this();
2383 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
2384 return anObj._retn();
2387 EqualTo_ptr FilterManager_i::CreateEqualTo()
2389 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
2390 SMESH::EqualTo_var anObj = aServant->_this();
2391 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
2392 return anObj._retn();
2395 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
2397 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
2398 SMESH::LogicalNOT_var anObj = aServant->_this();
2399 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
2400 return anObj._retn();
2403 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
2405 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
2406 SMESH::LogicalAND_var anObj = aServant->_this();
2407 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
2408 return anObj._retn();
2411 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
2413 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
2414 SMESH::LogicalOR_var anObj = aServant->_this();
2415 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
2416 return anObj._retn();
2419 LinearOrQuadratic_ptr FilterManager_i::CreateLinearOrQuadratic()
2421 SMESH::LinearOrQuadratic_i* aServant = new SMESH::LinearOrQuadratic_i();
2422 SMESH::LinearOrQuadratic_var anObj = aServant->_this();
2423 TPythonDump()<<aServant<<" = "<<this<<".CreateLinearOrQuadratic()";
2424 return anObj._retn();
2427 GroupColor_ptr FilterManager_i::CreateGroupColor()
2429 SMESH::GroupColor_i* aServant = new SMESH::GroupColor_i();
2430 SMESH::GroupColor_var anObj = aServant->_this();
2431 TPythonDump()<<aServant<<" = "<<this<<".CreateGroupColor()";
2432 return anObj._retn();
2435 ElemGeomType_ptr FilterManager_i::CreateElemGeomType()
2437 SMESH::ElemGeomType_i* aServant = new SMESH::ElemGeomType_i();
2438 SMESH::ElemGeomType_var anObj = aServant->_this();
2439 TPythonDump()<<aServant<<" = "<<this<<".CreateElemGeomType()";
2440 return anObj._retn();
2443 ElemEntityType_ptr FilterManager_i::CreateElemEntityType()
2445 SMESH::ElemEntityType_i* aServant = new SMESH::ElemEntityType_i();
2446 SMESH::ElemEntityType_var anObj = aServant->_this();
2447 TPythonDump()<<aServant<<" = "<<this<<".CreateElemEntityType()";
2448 return anObj._retn();
2451 Filter_ptr FilterManager_i::CreateFilter()
2453 SMESH::Filter_i* aServant = new SMESH::Filter_i();
2454 SMESH::Filter_var anObj = aServant->_this();
2455 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
2456 return anObj._retn();
2459 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
2461 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
2462 SMESH::FilterLibrary_var anObj = aServant->_this();
2463 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary('"<<aFileName<<"')";
2464 return anObj._retn();
2467 FilterLibrary_ptr FilterManager_i::CreateLibrary()
2469 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
2470 SMESH::FilterLibrary_var anObj = aServant->_this();
2471 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
2472 return anObj._retn();
2475 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
2477 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
2478 return remove( aFileName ) ? false : true;
2481 //=============================================================================
2483 * SMESH_Gen_i::CreateFilterManager
2485 * Create filter manager
2487 //=============================================================================
2489 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
2491 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2492 SMESH::FilterManager_var anObj = aFilter->_this();
2493 return anObj._retn();
2501 //=======================================================================
2502 // name : Filter_i::Filter_i
2503 // Purpose : Constructor
2504 //=======================================================================
2505 Filter_i::Filter_i()
2506 : myPredicate( NULL )
2509 //=======================================================================
2510 // name : Filter_i::~Filter_i
2511 // Purpose : Destructor
2512 //=======================================================================
2513 Filter_i::~Filter_i()
2516 myPredicate->UnRegister();
2518 if(!CORBA::is_nil(myMesh))
2519 myMesh->UnRegister();
2525 //=======================================================================
2526 // name : Filter_i::SetPredicate
2527 // Purpose : Set predicate
2528 //=======================================================================
2529 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
2532 myPredicate->UnRegister();
2534 myPredicate = SMESH::GetPredicate(thePredicate);
2538 myFilter.SetPredicate( myPredicate->GetPredicate() );
2539 myPredicate->Register();
2540 if ( const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh))
2541 myPredicate->GetPredicate()->SetMesh( aMesh );
2542 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
2544 NotifyerAndWaiter::Modified();
2547 //=======================================================================
2548 // name : Filter_i::GetElementType
2549 // Purpose : Get entity type
2550 //=======================================================================
2551 SMESH::ElementType Filter_i::GetElementType()
2553 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
2556 //=======================================================================
2557 // name : Filter_i::SetMesh
2558 // Purpose : Set mesh
2559 //=======================================================================
2562 SetMesh( SMESH_Mesh_ptr theMesh )
2564 if(!CORBA::is_nil(theMesh))
2565 theMesh->Register();
2567 if(!CORBA::is_nil(myMesh))
2568 myMesh->UnRegister();
2570 myMesh = SMESH_Mesh::_duplicate( theMesh );
2571 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
2574 if ( const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2575 myPredicate->GetPredicate()->SetMesh( aMesh );
2582 return GetElementsId(myMesh);
2585 //=======================================================================
2586 // name : Filter_i::GetElementsId
2587 // Purpose : Get ids of entities
2588 //=======================================================================
2591 GetElementsId( Predicate_i* thePredicate,
2592 const SMDS_Mesh* theMesh,
2593 Controls::Filter::TIdSequence& theSequence )
2596 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
2601 GetElementsId( Predicate_i* thePredicate,
2602 SMESH_Mesh_ptr theMesh,
2603 Controls::Filter::TIdSequence& theSequence )
2606 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2607 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
2612 GetElementsId( SMESH_Mesh_ptr theMesh )
2614 SMESH::long_array_var anArray = new SMESH::long_array;
2615 if(!CORBA::is_nil(theMesh) && myPredicate){
2617 Controls::Filter::TIdSequence aSequence;
2618 GetElementsId(myPredicate,theMesh,aSequence);
2619 long i = 0, iEnd = aSequence.size();
2620 anArray->length( iEnd );
2621 for ( ; i < iEnd; i++ )
2622 anArray[ i ] = aSequence[i];
2624 return anArray._retn();
2629 GetElementsIdFromParts( const ListOfIDSources& theParts )
2631 SMESH::long_array_var array = new SMESH::long_array;
2632 if ( theParts.length() > 0 && myPredicate )
2634 SMESH_Mesh_ptr mesh = theParts[0]->GetMesh();
2636 const SMDS_Mesh* meshDS = MeshPtr2SMDSMesh( mesh );
2637 Controls::Filter::TIdSequence totalSequence;
2638 for ( CORBA::ULong i = 0; i < theParts.length(); ++i )
2640 if ( SMESH::Filter_i* filter = SMESH::DownCast<SMESH::Filter_i*>( theParts[i] ))
2641 filter->SetMesh( mesh );
2642 SMDS_ElemIteratorPtr iter = SMESH_Mesh_i::GetElements( theParts[i], GetElementType() );
2643 if ( iter && meshDS )
2645 Controls::Filter::TIdSequence sequence;
2646 Controls::Filter::GetElementsId( meshDS, myPredicate->GetPredicate(), sequence, iter );
2647 totalSequence.insert( totalSequence.end(), sequence.begin(), sequence.end() );
2650 array->length( totalSequence.size() );
2651 for ( size_t i = 0; i < totalSequence.size(); ++i )
2652 array[ i ] = totalSequence[ i ];
2654 return array._retn();
2657 //=============================================================================
2659 * \brief Returns number of mesh elements per each \a EntityType
2661 //=============================================================================
2663 SMESH::long_array* ::Filter_i::GetMeshInfo()
2665 SMESH::long_array_var aRes = new SMESH::long_array();
2666 aRes->length(SMESH::Entity_Last);
2667 for (int i = 0; i < SMESH::Entity_Last; i++)
2670 if ( !CORBA::is_nil(myMesh) && myPredicate )
2672 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2673 SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2674 while ( it->more() )
2676 const SMDS_MeshElement* anElem = it->next();
2677 if ( myPredicate->IsSatisfy( anElem->GetID() ) )
2678 aRes[ anElem->GetEntityType() ]++;
2682 return aRes._retn();
2685 //=============================================================================
2687 * \brief Returns number of mesh elements of each \a ElementType
2689 //=============================================================================
2691 SMESH::long_array* ::Filter_i::GetNbElementsByType()
2693 SMESH::long_array_var aRes = new SMESH::long_array();
2694 aRes->length(SMESH::NB_ELEMENT_TYPES);
2695 for (int i = 0; i < SMESH::NB_ELEMENT_TYPES; i++)
2698 if ( !CORBA::is_nil(myMesh) && myPredicate ) {
2699 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2700 SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2701 CORBA::Long& nbElems = aRes[ GetElementType() ];
2702 while ( it->more() )
2704 const SMDS_MeshElement* anElem = it->next();
2705 if ( myPredicate->IsSatisfy( anElem->GetID() ) )
2710 return aRes._retn();
2714 //================================================================================
2716 * \brief Return GetElementType() within an array
2717 * Implement SMESH_IDSource interface
2719 //================================================================================
2721 SMESH::array_of_ElementType* Filter_i::GetTypes()
2723 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
2725 // check if any element passes through the filter
2726 if ( !CORBA::is_nil(myMesh) && myPredicate )
2728 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2729 SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2730 bool satisfies = false;
2731 while ( !satisfies && it->more() )
2732 satisfies = myPredicate->IsSatisfy( it->next()->GetID() );
2735 types[0] = GetElementType();
2738 return types._retn();
2741 //=======================================================================
2742 //function : GetMesh
2743 //purpose : Returns mesh
2744 //=======================================================================
2746 SMESH::SMESH_Mesh_ptr Filter_i::GetMesh()
2748 return SMESH_Mesh::_duplicate( myMesh );
2751 //=======================================================================
2752 //function : GetVtkUgStream
2753 //purpose : Return data vtk unstructured grid (not implemented)
2754 //=======================================================================
2756 SALOMEDS::TMPFile* Filter_i::GetVtkUgStream()
2758 SALOMEDS::TMPFile_var SeqFile;
2759 return SeqFile._retn();
2761 //=======================================================================
2762 // name : getCriteria
2763 // Purpose : Retrieve criterions from predicate
2764 //=======================================================================
2765 static inline void getPrediacates( Predicate_i* thePred,
2766 std::vector<Predicate_i*> & thePredVec )
2768 const int aFType = thePred->GetFunctorType();
2774 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2775 getPrediacates( aPred, thePredVec );
2781 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2782 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2783 getPrediacates( aPred1, thePredVec );
2784 getPrediacates( aPred2, thePredVec );
2789 thePredVec.push_back( thePred );
2792 //=======================================================================
2793 // name : getCriteria
2794 // Purpose : Retrieve criterions from predicate
2795 //=======================================================================
2796 static inline bool getCriteria( Predicate_i* thePred,
2797 SMESH::Filter::Criteria_out theCriteria )
2799 const int aFType = thePred->GetFunctorType();
2805 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2806 getCriteria( aPred, theCriteria );
2807 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2814 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2815 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2816 if ( !getCriteria( aPred1, theCriteria ) )
2818 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2819 return getCriteria( aPred2, theCriteria );
2825 // resize theCriteria
2826 CORBA::ULong i = theCriteria->length();
2827 theCriteria->length( i + 1 );
2828 theCriteria[ i ] = createCriterion();
2830 // set members of the added Criterion
2832 theCriteria[ i ].Type = aFType;
2833 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
2837 case FT_FreeBorders:
2840 case FT_LinearOrQuadratic:
2844 case FT_EqualVolumes:
2845 case FT_BadOrientedVolume:
2846 case FT_BareBorderVolume:
2847 case FT_BareBorderFace:
2848 case FT_OverConstrainedVolume:
2849 case FT_OverConstrainedFace:
2853 case FT_BelongToMeshGroup:
2855 BelongToMeshGroup_i* aPred = dynamic_cast<BelongToMeshGroup_i*>( thePred );
2856 SMESH::SMESH_GroupBase_var grp = aPred->GetGroup();
2857 if ( !grp->_is_nil() )
2859 theCriteria[ i ].ThresholdStr = grp->GetName();
2860 theCriteria[ i ].ThresholdID = aPred->GetGroupID().c_str();
2864 case FT_BelongToGeom:
2866 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
2867 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2868 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2869 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2872 case FT_BelongToPlane:
2873 case FT_BelongToCylinder:
2874 case FT_BelongToGenSurface:
2876 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
2877 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2878 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2879 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2882 case FT_LyingOnGeom:
2884 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
2885 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2886 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2887 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2890 case FT_CoplanarFaces:
2892 CoplanarFaces_i* aPred = dynamic_cast<CoplanarFaces_i*>( thePred );
2893 theCriteria[ i ].ThresholdID = aPred->GetFaceAsString();
2894 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2897 case FT_ConnectedElements:
2899 ConnectedElements_i* aPred = dynamic_cast<ConnectedElements_i*>( thePred );
2900 SMESH::ConnectedElements::ThresholdType type;
2901 CORBA::String_var threshold = aPred->GetThreshold( type );
2903 case SMESH::ConnectedElements::POINT:
2904 theCriteria[ i ].ThresholdStr = threshold; break;
2905 case SMESH::ConnectedElements::VERTEX:
2906 theCriteria[ i ].ThresholdID = threshold; break;
2907 case SMESH::ConnectedElements::NODE:
2908 theCriteria[ i ].Threshold = atof( threshold.in() ); break;
2915 EqualNodes_i* aPred = dynamic_cast<EqualNodes_i*>( thePred );
2916 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2921 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
2922 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
2929 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
2930 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
2931 theCriteria[ i ].Compare = aFType;
2932 theCriteria[ i ].Threshold = aCompar->GetMargin();
2933 if ( aFType == FT_EqualTo )
2935 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
2936 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
2942 GroupColor_i* aPred = dynamic_cast<GroupColor_i*>( thePred );
2943 theCriteria[ i ].ThresholdStr = aPred->GetColorStr();
2946 case FT_ElemGeomType:
2948 ElemGeomType_i* aPred = dynamic_cast<ElemGeomType_i*>( thePred );
2949 theCriteria[ i ].Threshold = (double)aPred->GetGeometryType();
2954 ElemEntityType_i* aPred = dynamic_cast<ElemEntityType_i*>( thePred );
2955 theCriteria[ i ].Threshold = (double)aPred->GetEntityType();
2963 //=======================================================================
2964 // name : Filter_i::GetCriteria
2965 // Purpose : Retrieve criterions from predicate
2966 //=======================================================================
2967 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2969 theCriteria = new SMESH::Filter::Criteria;
2970 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2973 //=======================================================================
2974 // name : Filter_i::SetCriteria
2975 // Purpose : Create new predicate and set criterions in it
2976 //=======================================================================
2977 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2979 SetPredicate( SMESH::Predicate::_nil() );
2981 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2982 FilterManager_ptr aFilterMgr = aFilter->_this();
2984 // CREATE two lists ( PREDICATES and LOG OP )
2987 TPythonDump()<<"aCriteria = []";
2988 std::list<SMESH::Predicate_ptr> aPredicates;
2989 std::list<int> aBinaries;
2990 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2992 int aCriterion = theCriteria[ i ].Type;
2993 int aCompare = theCriteria[ i ].Compare;
2994 double aThreshold = theCriteria[ i ].Threshold;
2995 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2996 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2997 int aUnary = theCriteria[ i ].UnaryOp;
2998 int aBinary = theCriteria[ i ].BinaryOp;
2999 double aTolerance = theCriteria[ i ].Tolerance;
3000 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
3001 long aPrecision = theCriteria[ i ].Precision;
3005 pd << "aCriterion = SMESH.Filter.Criterion("
3006 << aCriterion << ", "
3008 << aThreshold << ", '"
3009 << aThresholdStr << "', '"
3010 << aThresholdID << "', "
3013 << aTolerance << ", "
3014 << aTypeOfElem << ", "
3015 << aPrecision << ")";
3019 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
3020 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
3022 switch ( aCriterion )
3026 case SMESH::FT_MultiConnection:
3027 aFunctor = aFilterMgr->CreateMultiConnection();
3029 case SMESH::FT_MultiConnection2D:
3030 aFunctor = aFilterMgr->CreateMultiConnection2D();
3032 case SMESH::FT_Length:
3033 aFunctor = aFilterMgr->CreateLength();
3035 case SMESH::FT_Length2D:
3036 aFunctor = aFilterMgr->CreateLength2D();
3038 case SMESH::FT_Length3D:
3039 aFunctor = aFilterMgr->CreateLength3D();
3041 case SMESH::FT_Deflection2D:
3042 aFunctor = aFilterMgr->CreateDeflection2D();
3044 case SMESH::FT_AspectRatio:
3045 aFunctor = aFilterMgr->CreateAspectRatio();
3047 case SMESH::FT_AspectRatio3D:
3048 aFunctor = aFilterMgr->CreateAspectRatio3D();
3050 case SMESH::FT_Warping:
3051 aFunctor = aFilterMgr->CreateWarping();
3053 case SMESH::FT_MinimumAngle:
3054 aFunctor = aFilterMgr->CreateMinimumAngle();
3056 case SMESH::FT_Taper:
3057 aFunctor = aFilterMgr->CreateTaper();
3059 case SMESH::FT_Skew:
3060 aFunctor = aFilterMgr->CreateSkew();
3062 case SMESH::FT_Area:
3063 aFunctor = aFilterMgr->CreateArea();
3065 case SMESH::FT_Volume3D:
3066 aFunctor = aFilterMgr->CreateVolume3D();
3068 case SMESH::FT_MaxElementLength2D:
3069 aFunctor = aFilterMgr->CreateMaxElementLength2D();
3071 case SMESH::FT_MaxElementLength3D:
3072 aFunctor = aFilterMgr->CreateMaxElementLength3D();
3074 case SMESH::FT_BallDiameter:
3075 aFunctor = aFilterMgr->CreateBallDiameter();
3077 case SMESH::FT_NodeConnectivityNumber:
3078 aFunctor = aFilterMgr->CreateNodeConnectivityNumber();
3083 case SMESH::FT_FreeBorders:
3084 aPredicate = aFilterMgr->CreateFreeBorders();
3086 case SMESH::FT_FreeEdges:
3087 aPredicate = aFilterMgr->CreateFreeEdges();
3089 case SMESH::FT_FreeFaces:
3090 aPredicate = aFilterMgr->CreateFreeFaces();
3092 case SMESH::FT_FreeNodes:
3093 aPredicate = aFilterMgr->CreateFreeNodes();
3095 case SMESH::FT_EqualNodes:
3097 SMESH::EqualNodes_ptr pred = aFilterMgr->CreateEqualNodes();
3098 pred->SetTolerance( aTolerance );
3102 case SMESH::FT_EqualEdges:
3103 aPredicate = aFilterMgr->CreateEqualEdges();
3105 case SMESH::FT_EqualFaces:
3106 aPredicate = aFilterMgr->CreateEqualFaces();
3108 case SMESH::FT_EqualVolumes:
3109 aPredicate = aFilterMgr->CreateEqualVolumes();
3111 case SMESH::FT_BelongToMeshGroup:
3113 SMESH::BelongToMeshGroup_ptr tmpPred = aFilterMgr->CreateBelongToMeshGroup();
3114 tmpPred->SetGroupID( aThresholdID );
3115 aPredicate = tmpPred;
3118 case SMESH::FT_BelongToGeom:
3120 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
3121 tmpPred->SetElementType( aTypeOfElem );
3122 tmpPred->SetShape( aThresholdID, aThresholdStr );
3123 tmpPred->SetTolerance( aTolerance );
3124 aPredicate = tmpPred;
3127 case SMESH::FT_BelongToPlane:
3128 case SMESH::FT_BelongToCylinder:
3129 case SMESH::FT_BelongToGenSurface:
3131 SMESH::BelongToSurface_ptr tmpPred;
3132 switch ( aCriterion ) {
3133 case SMESH::FT_BelongToPlane:
3134 tmpPred = aFilterMgr->CreateBelongToPlane(); break;
3135 case SMESH::FT_BelongToCylinder:
3136 tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
3138 tmpPred = aFilterMgr->CreateBelongToGenSurface();
3140 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
3141 tmpPred->SetTolerance( aTolerance );
3142 aPredicate = tmpPred;
3145 case SMESH::FT_LyingOnGeom:
3147 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
3148 tmpPred->SetElementType( aTypeOfElem );
3149 tmpPred->SetShape( aThresholdID, aThresholdStr );
3150 tmpPred->SetTolerance( aTolerance );
3151 aPredicate = tmpPred;
3154 case SMESH::FT_RangeOfIds:
3156 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
3157 tmpPred->SetRangeStr( aThresholdStr );
3158 tmpPred->SetElementType( aTypeOfElem );
3159 aPredicate = tmpPred;
3162 case SMESH::FT_BadOrientedVolume:
3164 aPredicate = aFilterMgr->CreateBadOrientedVolume();
3167 case SMESH::FT_BareBorderVolume:
3169 aPredicate = aFilterMgr->CreateBareBorderVolume();
3172 case SMESH::FT_BareBorderFace:
3174 aPredicate = aFilterMgr->CreateBareBorderFace();
3177 case SMESH::FT_OverConstrainedVolume:
3179 aPredicate = aFilterMgr->CreateOverConstrainedVolume();
3182 case SMESH::FT_OverConstrainedFace:
3184 aPredicate = aFilterMgr->CreateOverConstrainedFace();
3187 case SMESH::FT_LinearOrQuadratic:
3189 SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
3190 tmpPred->SetElementType( aTypeOfElem );
3191 aPredicate = tmpPred;
3194 case SMESH::FT_GroupColor:
3196 SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor();
3197 tmpPred->SetElementType( aTypeOfElem );
3198 tmpPred->SetColorStr( aThresholdStr );
3199 aPredicate = tmpPred;
3202 case SMESH::FT_ElemGeomType:
3204 SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType();
3205 tmpPred->SetElementType( aTypeOfElem );
3206 tmpPred->SetGeometryType( (GeometryType)(int)(aThreshold + 0.5) );
3207 aPredicate = tmpPred;
3210 case SMESH::FT_EntityType:
3212 SMESH::ElemEntityType_ptr tmpPred = aFilterMgr->CreateElemEntityType();
3213 tmpPred->SetElementType( aTypeOfElem );
3214 tmpPred->SetEntityType( EntityType( (int (aThreshold + 0.5))));
3215 aPredicate = tmpPred;
3218 case SMESH::FT_CoplanarFaces:
3220 SMESH::CoplanarFaces_ptr tmpPred = aFilterMgr->CreateCoplanarFaces();
3221 tmpPred->SetFace( atol (aThresholdID ));
3222 tmpPred->SetTolerance( aTolerance );
3223 aPredicate = tmpPred;
3226 case SMESH::FT_ConnectedElements:
3228 SMESH::ConnectedElements_ptr tmpPred = aFilterMgr->CreateConnectedElements();
3229 if ( strlen( aThresholdID ) > 0 ) // shape ID
3230 tmpPred->SetThreshold( aThresholdID, SMESH::ConnectedElements::VERTEX );
3231 else if ( strlen( aThresholdStr ) > 0 ) // point coords
3232 tmpPred->SetThreshold( aThresholdStr, SMESH::ConnectedElements::POINT );
3233 else if ( aThreshold >= 1 )
3234 tmpPred->SetNode( (CORBA::Long) aThreshold ); // node ID
3235 tmpPred->SetElementType( aTypeOfElem );
3236 aPredicate = tmpPred;
3245 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
3247 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
3249 if ( aCompare == SMESH::FT_LessThan )
3250 aComparator = aFilterMgr->CreateLessThan();
3251 else if ( aCompare == SMESH::FT_MoreThan )
3252 aComparator = aFilterMgr->CreateMoreThan();
3253 else if ( aCompare == SMESH::FT_EqualTo )
3254 aComparator = aFilterMgr->CreateEqualTo();
3258 aComparator->SetNumFunctor( aFunctor );
3259 aComparator->SetMargin( aThreshold );
3261 if ( aCompare == FT_EqualTo )
3263 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
3264 anEqualTo->SetTolerance( aTolerance );
3267 aPredicate = aComparator;
3269 aFunctor->SetPrecision( aPrecision );
3273 if ( aUnary == FT_LogicalNOT )
3275 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
3276 aNotPred->SetPredicate( aPredicate );
3277 aPredicate = aNotPred;
3281 aPredicates.push_back( aPredicate );
3282 aBinaries.push_back( aBinary );
3283 pd <<"aCriteria.append(aCriterion)";
3286 TPythonDump pd; pd<<this<<".SetCriteria(aCriteria)";
3288 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
3290 // combine all "AND" operations
3292 std::list<SMESH::Predicate_ptr> aResList;
3294 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
3295 std::list<int>::iterator aBinaryIter;
3297 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
3298 int aPrevBinary = SMESH::FT_Undefined;
3299 if ( !aBinaries.empty() )
3300 aBinaries.back() = SMESH::FT_Undefined;
3302 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
3303 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
3304 ++aPredIter, ++aBinaryIter )
3306 int aCurrBinary = *aBinaryIter;
3308 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
3310 if ( aPrevBinary == SMESH::FT_LogicalAND )
3313 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
3314 aBinaryPred->SetPredicate1( aPrevPredicate );
3315 aBinaryPred->SetPredicate2( *aPredIter );
3316 aCurrPred = aBinaryPred;
3319 aCurrPred = *aPredIter;
3321 if ( aCurrBinary != SMESH::FT_LogicalAND )
3322 aResList.push_back( aCurrPred );
3324 aPrevPredicate = aCurrPred;
3325 aPrevBinary = aCurrBinary;
3328 // combine all "OR" operations
3330 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
3332 if ( aResList.size() == 1 )
3333 aResPredicate = *aResList.begin();
3334 else if ( aResList.size() > 1 )
3336 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
3337 aResPredicate = *anIter;
3339 for ( ; anIter != aResList.end(); ++anIter )
3341 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
3342 aBinaryPred->SetPredicate1( aResPredicate );
3343 aBinaryPred->SetPredicate2( *anIter );
3344 aResPredicate = aBinaryPred;
3348 SetPredicate( aResPredicate );
3349 if ( !aResPredicate->_is_nil() )
3350 aResPredicate->UnRegister();
3352 return !aResPredicate->_is_nil();
3355 //=======================================================================
3356 // name : Filter_i::GetPredicate_i
3357 // Purpose : Get implementation of predicate
3358 //=======================================================================
3359 Predicate_i* Filter_i::GetPredicate_i()
3364 //=======================================================================
3365 // name : Filter_i::GetPredicate
3366 // Purpose : Get predicate
3367 //=======================================================================
3368 Predicate_ptr Filter_i::GetPredicate()
3370 if ( myPredicate == 0 )
3371 return SMESH::Predicate::_nil();
3374 SMESH::Predicate_var anObj = myPredicate->_this();
3375 // if ( SMESH::Functor_i* fun = SMESH::DownCast<SMESH::Functor_i*>( anObj ))
3376 // TPythonDump() << fun << " = " << this << ".GetPredicate()";
3377 return anObj._retn();
3381 //================================================================================
3383 * \brief Find groups it depends on
3385 //================================================================================
3387 void Filter_i::FindBaseObjects()
3389 // release current groups
3390 for ( size_t i = 0; i < myBaseGroups.size(); ++i )
3391 if ( myBaseGroups[i] )
3393 myBaseGroups[i]->RemoveModifWaiter( this );
3394 myBaseGroups[i]->UnRegister();
3397 // remember new groups
3398 myBaseGroups.clear();
3401 std::vector<Predicate_i*> predicates;
3402 getPrediacates( myPredicate, predicates );
3403 for ( size_t i = 0; i < predicates.size(); ++i )
3404 if ( BelongToMeshGroup_i* bmg = dynamic_cast< BelongToMeshGroup_i* >( predicates[i] ))
3406 SMESH::SMESH_GroupBase_var g = bmg->GetGroup();
3407 SMESH_GroupBase_i* g_i = SMESH::DownCast< SMESH_GroupBase_i*>( g );
3410 g_i->AddModifWaiter( this );
3412 myBaseGroups.push_back( g_i );
3418 //================================================================================
3420 * \brief When notified on removal of myBaseGroups[i], remove a reference to a
3421 * group from a predicate
3423 //================================================================================
3425 void Filter_i::OnBaseObjModified(NotifyerAndWaiter* group, bool removed)
3428 return; // a GroupOnFilter holding this filter is notified automatically
3432 std::vector<Predicate_i*> predicates;
3433 getPrediacates( myPredicate, predicates );
3434 for ( size_t i = 0; i < predicates.size(); ++i )
3435 if ( BelongToMeshGroup_i* bmg = dynamic_cast< BelongToMeshGroup_i* >( predicates[i] ))
3437 SMESH::SMESH_GroupBase_var g = bmg->GetGroup();
3438 SMESH_GroupBase_i* g_i = SMESH::DownCast< SMESH_GroupBase_i*>( g );
3441 bmg->SetGroup( SMESH::SMESH_GroupBase::_nil() );
3442 bmg->SetGroupID( "" );
3447 FindBaseObjects(); // release and update myBaseGroups;
3454 #define ATTR_TYPE "type"
3455 #define ATTR_COMPARE "compare"
3456 #define ATTR_THRESHOLD "threshold"
3457 #define ATTR_UNARY "unary"
3458 #define ATTR_BINARY "binary"
3459 #define ATTR_THRESHOLD_STR "threshold_str"
3460 #define ATTR_TOLERANCE "tolerance"
3461 #define ATTR_ELEMENT_TYPE "ElementType"
3463 //=======================================================================
3465 // Purpose : Convert bool to LDOMString
3466 //=======================================================================
3467 static inline LDOMString toString( CORBA::Boolean val )
3469 return val ? "logical not" : "";
3472 //=======================================================================
3474 // Purpose : Convert LDOMString to bool
3475 //=======================================================================
3476 static inline bool toBool( const LDOMString& theStr )
3478 return theStr.equals( "logical not" );
3481 //=======================================================================
3483 // Purpose : Convert double to LDOMString
3484 //=======================================================================
3485 static inline LDOMString toString( CORBA::Double val )
3488 sprintf( a, "%e", val );
3489 return LDOMString( a );
3492 //=======================================================================
3494 // Purpose : Convert LDOMString to double
3495 //=======================================================================
3496 static inline double toDouble( const LDOMString& theStr )
3498 return atof( theStr.GetString() );
3501 //=======================================================================
3503 // Purpose : Convert functor type to LDOMString
3504 //=======================================================================
3505 static inline LDOMString toString( CORBA::Long theType )
3509 case FT_AspectRatio : return "Aspect ratio";
3510 case FT_Warping : return "Warping";
3511 case FT_MinimumAngle : return "Minimum angle";
3512 case FT_Taper : return "Taper";
3513 case FT_Skew : return "Skew";
3514 case FT_Area : return "Area";
3515 case FT_Volume3D : return "Volume3D";
3516 case FT_MaxElementLength2D : return "Max element length 2D";
3517 case FT_MaxElementLength3D : return "Max element length 3D";
3518 case FT_BelongToMeshGroup : return "Belong to Mesh Group";
3519 case FT_BelongToGeom : return "Belong to Geom";
3520 case FT_BelongToPlane : return "Belong to Plane";
3521 case FT_BelongToCylinder : return "Belong to Cylinder";
3522 case FT_BelongToGenSurface : return "Belong to Generic Surface";
3523 case FT_LyingOnGeom : return "Lying on Geom";
3524 case FT_BadOrientedVolume : return "Bad Oriented Volume";
3525 case FT_BareBorderVolume : return "Volumes with bare border";
3526 case FT_BareBorderFace : return "Faces with bare border";
3527 case FT_OverConstrainedVolume : return "Over-constrained Volumes";
3528 case FT_OverConstrainedFace : return "Over-constrained Faces";
3529 case FT_RangeOfIds : return "Range of IDs";
3530 case FT_FreeBorders : return "Free borders";
3531 case FT_FreeEdges : return "Free edges";
3532 case FT_FreeFaces : return "Free faces";
3533 case FT_FreeNodes : return "Free nodes";
3534 case FT_EqualNodes : return "Equal nodes";
3535 case FT_EqualEdges : return "Equal edges";
3536 case FT_EqualFaces : return "Equal faces";
3537 case FT_EqualVolumes : return "Equal volumes";
3538 case FT_MultiConnection : return "Borders at multi-connections";
3539 case FT_MultiConnection2D : return "Borders at multi-connections 2D";
3540 case FT_Length : return "Length";
3541 case FT_Length2D : return "Length 2D";
3542 case FT_Length3D : return "Length 3D";
3543 case FT_Deflection2D : return "Deflection 2D";
3544 case FT_LessThan : return "Less than";
3545 case FT_MoreThan : return "More than";
3546 case FT_EqualTo : return "Equal to";
3547 case FT_LogicalNOT : return "Not";
3548 case FT_LogicalAND : return "And";
3549 case FT_LogicalOR : return "Or";
3550 case FT_GroupColor : return "Color of Group";
3551 case FT_LinearOrQuadratic : return "Linear or Quadratic";
3552 case FT_ElemGeomType : return "Element geometry type";
3553 case FT_EntityType : return "Entity type";
3554 case FT_Undefined : return "";
3555 default : return "";
3559 //=======================================================================
3560 // name : toFunctorType
3561 // Purpose : Convert LDOMString to functor type
3562 //=======================================================================
3563 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
3565 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
3566 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
3567 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
3568 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
3569 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
3570 else if ( theStr.equals( "Area" ) ) return FT_Area;
3571 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
3572 else if ( theStr.equals( "Max element length 2D" ) ) return FT_MaxElementLength2D;
3573 else if ( theStr.equals( "Max element length 3D" ) ) return FT_MaxElementLength3D;
3574 else if ( theStr.equals( "Belong to Mesh Group" ) ) return FT_BelongToMeshGroup;
3575 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
3576 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
3577 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
3578 else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface;
3579 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
3580 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
3581 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
3582 else if ( theStr.equals( "Free faces" ) ) return FT_FreeFaces;
3583 else if ( theStr.equals( "Free nodes" ) ) return FT_FreeNodes;
3584 else if ( theStr.equals( "Equal nodes" ) ) return FT_EqualNodes;
3585 else if ( theStr.equals( "Equal edges" ) ) return FT_EqualEdges;
3586 else if ( theStr.equals( "Equal faces" ) ) return FT_EqualFaces;
3587 else if ( theStr.equals( "Equal volumes" ) ) return FT_EqualVolumes;
3588 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
3589 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
3590 else if ( theStr.equals( "Length" ) ) return FT_Length;
3591 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
3592 // else if ( theStr.equals( "Length3D" ) ) return FT_Length3D;
3593 else if ( theStr.equals( "Deflection" ) ) return FT_Deflection2D;
3594 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
3595 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
3596 else if ( theStr.equals( "Volumes with bare border" ) ) return FT_BareBorderVolume;
3597 else if ( theStr.equals( "Faces with bare border" ) ) return FT_BareBorderFace;
3598 else if ( theStr.equals( "Over-constrained Volumes" ) ) return FT_OverConstrainedVolume;
3599 else if ( theStr.equals( "Over-constrained Faces" ) ) return FT_OverConstrainedFace;
3600 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
3601 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
3602 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
3603 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
3604 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
3605 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
3606 else if ( theStr.equals( "Color of Group" ) ) return FT_GroupColor;
3607 else if ( theStr.equals( "Linear or Quadratic" ) ) return FT_LinearOrQuadratic;
3608 else if ( theStr.equals( "Element geometry type" ) ) return FT_ElemGeomType;
3609 else if ( theStr.equals( "Entity type" ) ) return FT_EntityType;
3610 else if ( theStr.equals( "" ) ) return FT_Undefined;
3611 else return FT_Undefined;
3614 //=======================================================================
3615 // name : toFunctorType
3616 // Purpose : Convert LDOMString to value of ElementType enumeration
3617 //=======================================================================
3618 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
3620 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
3621 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
3622 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
3623 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
3624 else return SMESH::ALL;
3627 //=======================================================================
3629 // Purpose : Convert ElementType to string
3630 //=======================================================================
3631 static inline LDOMString toString( const SMESH::ElementType theType )
3635 case SMESH::NODE : return "NODE";
3636 case SMESH::EDGE : return "EDGE";
3637 case SMESH::FACE : return "FACE";
3638 case SMESH::VOLUME : return "VOLUME";
3639 case SMESH::ALL : return "ALL";
3640 default : return "";
3644 //=======================================================================
3645 // name : findFilter
3646 // Purpose : Find filter in document
3647 //=======================================================================
3648 static LDOM_Element findFilter( const char* theFilterName,
3649 const LDOM_Document& theDoc,
3650 LDOM_Node* theParent = 0 )
3652 LDOM_Element aRootElement = theDoc.getDocumentElement();
3653 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
3654 return LDOM_Element();
3656 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
3657 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
3659 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
3660 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3662 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
3663 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
3664 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
3666 if ( theParent != 0 )
3667 *theParent = aTypeNode;
3668 return (LDOM_Element&)aFilter;
3672 return LDOM_Element();
3675 //=======================================================================
3676 // name : getSectionName
3677 // Purpose : Get name of section of filters
3678 //=======================================================================
3679 static const char* getSectionName( const ElementType theType )
3683 case SMESH::NODE : return "Filters for nodes";
3684 case SMESH::EDGE : return "Filters for edges";
3685 case SMESH::FACE : return "Filters for faces";
3686 case SMESH::VOLUME : return "Filters for volumes";
3687 case SMESH::ALL : return "Filters for elements";
3688 default : return "";
3692 //=======================================================================
3693 // name : getSection
3694 // Purpose : Create section for filters corresponding to the entity type
3695 //=======================================================================
3696 static LDOM_Node getSection( const ElementType theType,
3697 LDOM_Document& theDoc,
3698 const bool toCreate = false )
3700 LDOM_Element aRootElement = theDoc.getDocumentElement();
3701 if ( aRootElement.isNull() )
3705 bool anExist = false;
3706 const char* aSectionName = getSectionName( theType );
3707 if ( strcmp( aSectionName, "" ) == 0 )
3710 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
3712 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
3714 aNode = aSections.item( i );
3715 LDOM_Element& anItem = ( LDOM_Element& )aNode;
3716 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
3723 // Create new section if necessary
3728 LDOM_Element aNewItem = theDoc.createElement( "section" );
3729 aNewItem.setAttribute( "name", aSectionName );
3730 aRootElement.appendChild( aNewItem );
3740 //=======================================================================
3741 // name : createFilterItem
3742 // Purpose : Create filter item or LDOM document
3743 //=======================================================================
3744 static LDOM_Element createFilterItem( const char* theName,
3745 SMESH::Filter_ptr theFilter,
3746 LDOM_Document& theDoc )
3748 // create new filter in document
3749 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
3750 aFilterItem.setAttribute( "name", theName );
3752 // save filter criterions
3753 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3755 if ( !theFilter->GetCriteria( aCriteria ) )
3756 return LDOM_Element();
3758 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
3760 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
3762 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
3763 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
3764 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
3765 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
3766 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
3768 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
3769 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
3770 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
3771 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
3773 aFilterItem.appendChild( aCriterionItem );
3779 //=======================================================================
3780 // name : FilterLibrary_i::FilterLibrary_i
3781 // Purpose : Constructor
3782 //=======================================================================
3783 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
3785 myFileName = CORBA::string_dup( theFileName );
3786 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
3787 myFilterMgr = aFilterMgr->_this();
3791 // Try to use existing library file
3792 bool anExists = false;
3793 if ( !aParser.parse( myFileName ) )
3795 myDoc = aParser.getDocument();
3798 // Create a new XML document if it doesn't exist
3800 myDoc = LDOM_Document::createDocument( LDOMString() );
3802 LDOM_Element aRootElement = myDoc.getDocumentElement();
3803 if ( aRootElement.isNull() )
3805 // If the existing document is empty --> try to create a new one
3807 myDoc = LDOM_Document::createDocument( LDOMString() );
3811 //=======================================================================
3812 // name : FilterLibrary_i::FilterLibrary_i
3813 // Purpose : Constructor
3814 //=======================================================================
3815 FilterLibrary_i::FilterLibrary_i()
3818 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
3819 myFilterMgr = aFilter->_this();
3821 myDoc = LDOM_Document::createDocument( LDOMString() );
3824 FilterLibrary_i::~FilterLibrary_i()
3826 CORBA::string_free( myFileName );
3827 //TPythonDump()<<this<<".UnRegister()";
3830 //=======================================================================
3831 // name : FilterLibrary_i::Copy
3832 // Purpose : Create filter and initialize it with values from library
3833 //=======================================================================
3834 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
3836 Filter_ptr aRes = Filter::_nil();
3837 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
3839 if ( aFilter.isNull() )
3842 std::list<SMESH::Filter::Criterion> aCriteria;
3844 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
3845 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
3847 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
3849 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
3850 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
3851 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
3852 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
3853 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
3855 SMESH::Filter::Criterion aCriterion = createCriterion();
3857 aCriterion.Type = toFunctorType( aTypeStr );
3858 aCriterion.Compare = toFunctorType( aCompareStr );
3859 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
3860 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
3862 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
3864 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
3866 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3867 ? val : atof( str.GetString() );
3869 str = aCrit->getAttribute( ATTR_TOLERANCE );
3870 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3871 ? val : atof( str.GetString() );
3873 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
3874 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
3877 sprintf( a, "%d", val );
3878 aCriterion.ThresholdStr = CORBA::string_dup( a );
3881 aCriterion.ThresholdStr = str.GetString();
3883 aCriteria.push_back( aCriterion );
3886 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
3887 aCriteriaVar->length( aCriteria.size() );
3890 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
3892 for( ; anIter != aCriteria.end(); ++anIter )
3893 aCriteriaVar[ i++ ] = *anIter;
3895 aRes = myFilterMgr->CreateFilter();
3896 aRes->SetCriteria( aCriteriaVar.inout() );
3898 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
3903 //=======================================================================
3904 // name : FilterLibrary_i::SetFileName
3905 // Purpose : Set file name for library
3906 //=======================================================================
3907 void FilterLibrary_i::SetFileName( const char* theFileName )
3909 CORBA::string_free( myFileName );
3910 myFileName = CORBA::string_dup( theFileName );
3911 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
3914 //=======================================================================
3915 // name : FilterLibrary_i::GetFileName
3916 // Purpose : Get file name of library
3917 //=======================================================================
3918 char* FilterLibrary_i::GetFileName()
3920 return CORBA::string_dup( myFileName );
3923 //=======================================================================
3924 // name : FilterLibrary_i::Add
3925 // Purpose : Add new filter to library
3926 //=======================================================================
3927 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
3929 // if filter already in library or entry filter is null do nothing
3930 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3931 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
3934 // get section corresponding to the filter type
3935 ElementType anEntType = theFilter->GetElementType();
3937 LDOM_Node aSection = getSection( anEntType, myDoc, true );
3938 if ( aSection.isNull() )
3941 // create filter item
3942 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
3943 if ( aFilterItem.isNull() )
3947 aSection.appendChild( aFilterItem );
3948 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3949 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
3954 //=======================================================================
3955 // name : FilterLibrary_i::Add
3956 // Purpose : Add new filter to library
3957 //=======================================================================
3958 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
3960 // if filter already in library or entry filter is null do nothing
3961 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3962 if ( !aFilterNode.isNull() )
3965 LDOM_Node aSection = getSection( theType, myDoc, true );
3966 if ( aSection.isNull() )
3969 // create filter item
3970 Filter_var aFilter = myFilterMgr->CreateFilter();
3972 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
3973 if ( aFilterItem.isNull() )
3977 aSection.appendChild( aFilterItem );
3978 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
3983 //=======================================================================
3984 // name : FilterLibrary_i::Delete
3985 // Purpose : Delete filter from library
3986 //=======================================================================
3987 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
3989 LDOM_Node aParentNode;
3990 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
3991 if ( aFilterNode.isNull() || aParentNode.isNull() )
3994 aParentNode.removeChild( aFilterNode );
3995 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
3999 //=======================================================================
4000 // name : FilterLibrary_i::Replace
4001 // Purpose : Replace existing filter with entry filter.
4002 // IMPORTANT : If filter does not exist it is not created
4003 //=======================================================================
4004 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
4005 const char* theNewName,
4006 Filter_ptr theFilter )
4008 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
4009 if ( aFilterItem.isNull() || theFilter->_is_nil() )
4012 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
4013 if ( aNewItem.isNull() )
4017 aFilterItem.ReplaceElement( aNewItem );
4018 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
4019 TPythonDump()<<this<<".Replace('"<<theFilterName<<"','"<<theNewName<<"',"<<aFilter<<")";
4024 //=======================================================================
4025 // name : FilterLibrary_i::Save
4026 // Purpose : Save library on disk
4027 //=======================================================================
4028 CORBA::Boolean FilterLibrary_i::Save()
4030 if ( myFileName == 0 || strlen( myFileName ) == 0 )
4034 fb.open( myFileName, std::ios::out );
4036 Standard_OStream os( &fb );
4038 LDOM_XmlWriter aWriter;
4039 aWriter.SetIndentation( 2 );
4040 aWriter.Write( os, myDoc );
4043 TPythonDump()<<this<<".Save()";
4047 //=======================================================================
4048 // name : FilterLibrary_i::SaveAs
4049 // Purpose : Save library on disk
4050 //=======================================================================
4051 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
4053 myFileName = strdup ( aFileName );
4054 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
4058 //=======================================================================
4059 // name : FilterLibrary_i::IsPresent
4060 // Purpose : Verify whether filter is in library
4061 //=======================================================================
4062 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
4064 return !findFilter( theFilterName, myDoc ).isNull();
4067 //=======================================================================
4068 // name : FilterLibrary_i::NbFilters
4069 // Purpose : Return amount of filters in library
4070 //=======================================================================
4071 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
4073 string_array_var aNames = GetNames( theType );
4074 return aNames->length();
4077 //=======================================================================
4078 // name : FilterLibrary_i::GetNames
4079 // Purpose : Get names of filters from library
4080 //=======================================================================
4081 string_array* FilterLibrary_i::GetNames( ElementType theType )
4083 string_array_var anArray = new string_array;
4084 TColStd_SequenceOfHAsciiString aSeq;
4086 LDOM_Node aSection = getSection( theType, myDoc, false );
4088 if ( !aSection.isNull() )
4090 for ( LDOM_Node aFilter = aSection.getFirstChild();
4091 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
4093 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
4094 aSeq.Append( new TCollection_HAsciiString(
4095 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
4099 anArray->length( aSeq.Length() );
4100 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
4101 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
4103 return anArray._retn();
4106 //=======================================================================
4107 // name : FilterLibrary_i::GetAllNames
4108 // Purpose : Get names of filters from library
4109 //=======================================================================
4110 string_array* FilterLibrary_i::GetAllNames()
4112 string_array_var aResArray = new string_array;
4113 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
4115 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
4117 int aPrevLength = aResArray->length();
4118 aResArray->length( aPrevLength + aNames->length() );
4119 for ( int i = 0, n = aNames->length(); i < n; i++ )
4120 aResArray[ aPrevLength + i ] = aNames[ i ];
4123 return aResArray._retn();
4126 //================================================================================
4128 * \brief Return an array of strings corresponding to items of enum FunctorType
4130 //================================================================================
4132 static const char** getFunctNames()
4134 static const char* functName[] = {
4135 // IT's necessary to update this array according to enum FunctorType (SMESH_Filter.idl)
4136 // The order is IMPORTANT !!!
4145 "FT_MaxElementLength2D",
4146 "FT_MaxElementLength3D",
4155 "FT_MultiConnection",
4156 "FT_MultiConnection2D",
4161 "FT_NodeConnectivityNumber",
4162 "FT_BelongToMeshGroup",
4165 "FT_BelongToCylinder",
4166 "FT_BelongToGenSurface",
4169 "FT_BadOrientedVolume",
4170 "FT_BareBorderVolume",
4171 "FT_BareBorderFace",
4172 "FT_OverConstrainedVolume",
4173 "FT_OverConstrainedFace",
4174 "FT_LinearOrQuadratic",
4180 "FT_ConnectedElements",
4190 // check if functName is complete, compilation failure means that enum FunctorType changed
4191 const int nbFunctors = sizeof(functName) / sizeof(const char*);
4192 int _assert[( nbFunctors == SMESH::FT_Undefined + 1 ) ? 2 : -1 ]; _assert[0]=_assert[1]=0;
4198 //================================================================================
4200 * \brief Return a string corresponding to an item of enum FunctorType
4202 //================================================================================
4204 const char* SMESH::FunctorTypeToString(SMESH::FunctorType ft)
4206 if ( ft < 0 || ft > SMESH::FT_Undefined )
4207 return "FT_Undefined";
4208 return getFunctNames()[ ft ];
4211 //================================================================================
4213 * \brief Converts a string to FunctorType. This is reverse of FunctorTypeToString()
4215 //================================================================================
4217 SMESH::FunctorType SMESH::StringToFunctorType(const char* str)
4219 std::string name( str + 3 ); // skip "FT_"
4220 const char** functNames = getFunctNames();
4222 for ( ; ft < SMESH::FT_Undefined; ++ft )
4223 if ( name == ( functNames[ft] + 3 ))
4226 //ASSERT( strcmp( str, FunctorTypeToString( SMESH::FunctorType( ft ))) == 0 );
4228 return SMESH::FunctorType( ft );
4231 //================================================================================
4233 * \brief calls OnBaseObjModified(), if who != this, and myWaiters[i]->Modified(who)
4235 //================================================================================
4237 void NotifyerAndWaiter::Modified( bool removed, NotifyerAndWaiter* who )
4239 if ( who != 0 && who != this )
4240 OnBaseObjModified( who, removed );
4244 std::list<NotifyerAndWaiter*> waiters = myWaiters; // myWaiters can be changed by Modified()
4245 std::list<NotifyerAndWaiter*>::iterator i = waiters.begin();
4246 for ( ; i != waiters.end(); ++i )
4247 (*i)->Modified( removed, who );
4250 //================================================================================
4252 * \brief Stores an object to be notified on change of predicate
4254 //================================================================================
4256 void NotifyerAndWaiter::AddModifWaiter( NotifyerAndWaiter* waiter )
4259 myWaiters.push_back( waiter );
4262 //================================================================================
4264 * \brief Removes an object to be notified on change of predicate
4266 //================================================================================
4268 void NotifyerAndWaiter::RemoveModifWaiter( NotifyerAndWaiter* waiter )
4270 myWaiters.remove( waiter );
4273 //================================================================================
4275 * \brief Checks if a waiter is among myWaiters, maybe nested
4277 //================================================================================
4279 bool NotifyerAndWaiter::ContainModifWaiter( NotifyerAndWaiter* waiter )
4281 bool is = ( waiter == this );
4283 std::list<NotifyerAndWaiter*>::iterator w = myWaiters.begin();
4284 for ( ; !is && w != myWaiters.end(); ++w )
4285 is = (*w)->ContainModifWaiter( waiter );