1 // Copyright (C) 2007-2020 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 )
141 aList = SMESH_Gen_i::getStudyServant()->FindObjectByName( theName, "SHAPERSTUDY" );
142 if ( aList->length() > 0 )
144 CORBA::Object_var anObj = aList[ 0 ]->GetObject();
145 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( anObj );
146 TopoDS_Shape shape = aSMESHGen->GeomObjectToShape( aGeomObj );
147 SALOME::UnRegister( aList ); // UnRegister() objects in aList
151 return TopoDS_Shape();
154 static TopoDS_Shape getShapeByID (const char* theID)
156 if ( theID && strlen( theID ) > 0 ) {
157 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
158 SALOMEDS::SObject_wrap aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID(theID);
159 if ( !aSObj->_is_nil() ) {
160 CORBA::Object_var obj = aSObj->GetObject();
161 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
162 return aSMESHGen->GeomObjectToShape( aGeomObj );
165 return TopoDS_Shape();
168 // static std::string getShapeNameByID (const char* theID)
170 // if ( theID && strlen( theID ) > 0 ) {
171 // SALOMEDS::SObject_wrap aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID(theID);
172 // if ( !aSObj->_is_nil() ) {
173 // CORBA::String_var name = aSObj->GetName();
186 Description : An abstract class for all functors
188 Functor_i::Functor_i():
189 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
191 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
192 //PortableServer::ObjectId_var anObjectId =
193 // SMESH_Gen_i::GetPOA()->activate_object( this );
196 Functor_i::~Functor_i()
198 //TPythonDump()<<this<<".UnRegister()";
201 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
203 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
204 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
207 ElementType Functor_i::GetElementType()
209 return ( ElementType )myFunctorPtr->GetType();
214 Class : NumericalFunctor_i
215 Description : Base class for numerical functors
217 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
219 return myNumericalFunctorPtr->GetValue( theId );
222 CORBA::Boolean NumericalFunctor_i::IsApplicable( CORBA::Long theElementId )
224 return myNumericalFunctorPtr->IsApplicable( theElementId );
227 SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals, CORBA::Boolean isLogarithmic)
229 std::vector<int> nbEvents;
230 std::vector<double> funValues;
231 std::vector<int> elements;
232 myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements,0,isLogarithmic);
234 SMESH::Histogram_var histogram = new SMESH::Histogram;
236 nbIntervals = CORBA::Short( Min( int( nbEvents.size()),
237 int( funValues.size() - 1 )));
238 if ( nbIntervals > 0 )
240 histogram->length( nbIntervals );
241 for ( int i = 0; i < nbIntervals; ++i )
243 HistogramRectangle& rect = histogram[i];
244 rect.nbEvents = nbEvents[i];
245 rect.min = funValues[i];
246 rect.max = funValues[i+1];
249 return histogram._retn();
252 SMESH::Histogram* NumericalFunctor_i::GetLocalHistogram(CORBA::Short nbIntervals,
253 CORBA::Boolean isLogarithmic,
254 SMESH::SMESH_IDSource_ptr object)
256 SMESH::Histogram_var histogram = new SMESH::Histogram;
258 std::vector<int> nbEvents;
259 std::vector<double> funValues;
260 std::vector<int> elements;
262 SMDS_ElemIteratorPtr elemIt;
263 if ( SMESH::DownCast< SMESH_GroupOnFilter_i* >( object ) ||
264 SMESH::DownCast< SMESH::Filter_i* >( object ))
266 elemIt = SMESH_Mesh_i::GetElements( object, GetElementType() );
267 if ( !elemIt ) return histogram._retn();
271 SMESH::SMESH_Mesh_var mesh = object->GetMesh();
272 SMESH::long_array_var objNbElems = object->GetNbElementsByType();
273 SMESH::long_array_var meshNbElems = mesh-> GetNbElementsByType();
274 if ( meshNbElems[ GetElementType() ] !=
275 objNbElems [ GetElementType() ] )
277 elements.reserve( objNbElems[ GetElementType() ]);
278 elemIt = SMESH_Mesh_i::GetElements( object, GetElementType() );
283 while ( elemIt->more() )
284 elements.push_back( elemIt->next()->GetID() );
285 if ( elements.empty() ) return histogram._retn();
288 myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements,0,isLogarithmic);
290 nbIntervals = CORBA::Short( Min( int( nbEvents.size()),
291 int( funValues.size() - 1 )));
292 if ( nbIntervals > 0 )
294 histogram->length( nbIntervals );
295 for ( int i = 0; i < nbIntervals; ++i )
297 HistogramRectangle& rect = histogram[i];
298 rect.nbEvents = nbEvents[i];
299 rect.min = funValues[i];
300 rect.max = funValues[i+1];
303 return histogram._retn();
306 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
308 myNumericalFunctorPtr->SetPrecision( thePrecision );
309 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
312 CORBA::Long NumericalFunctor_i::GetPrecision()
314 return myNumericalFunctorPtr->GetPrecision();
317 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
319 return myNumericalFunctorPtr;
324 Class : SMESH_MinimumAngle
325 Description : Functor for calculation of minimum angle
327 MinimumAngle_i::MinimumAngle_i()
329 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
330 myFunctorPtr = myNumericalFunctorPtr;
333 FunctorType MinimumAngle_i::GetFunctorType()
335 return SMESH::FT_MinimumAngle;
341 Description : Functor for calculating aspect ratio
343 AspectRatio_i::AspectRatio_i()
345 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
346 myFunctorPtr = myNumericalFunctorPtr;
349 FunctorType AspectRatio_i::GetFunctorType()
351 return SMESH::FT_AspectRatio;
356 Class : AspectRatio3D
357 Description : Functor for calculating aspect ratio 3D
359 AspectRatio3D_i::AspectRatio3D_i()
361 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
362 myFunctorPtr = myNumericalFunctorPtr;
365 FunctorType AspectRatio3D_i::GetFunctorType()
367 return SMESH::FT_AspectRatio3D;
373 Description : Functor for calculating warping
375 Warping_i::Warping_i()
377 myNumericalFunctorPtr.reset( new Controls::Warping() );
378 myFunctorPtr = myNumericalFunctorPtr;
381 FunctorType Warping_i::GetFunctorType()
383 return SMESH::FT_Warping;
389 Description : Functor for calculating taper
393 myNumericalFunctorPtr.reset( new Controls::Taper() );
394 myFunctorPtr = myNumericalFunctorPtr;
397 FunctorType Taper_i::GetFunctorType()
399 return SMESH::FT_Taper;
404 Description : Functor for calculating skew in degrees
408 myNumericalFunctorPtr.reset( new Controls::Skew() );
409 myFunctorPtr = myNumericalFunctorPtr;
412 FunctorType Skew_i::GetFunctorType()
414 return SMESH::FT_Skew;
419 Description : Functor for calculating area
423 myNumericalFunctorPtr.reset( new Controls::Area() );
424 myFunctorPtr = myNumericalFunctorPtr;
427 FunctorType Area_i::GetFunctorType()
429 return SMESH::FT_Area;
434 Description : Functor for calculating volume of 3D element
436 Volume3D_i::Volume3D_i()
438 myNumericalFunctorPtr.reset( new Controls::Volume() );
439 myFunctorPtr = myNumericalFunctorPtr;
442 FunctorType Volume3D_i::GetFunctorType()
444 return SMESH::FT_Volume3D;
448 Class : MaxElementLength2D_i
449 Description : Functor for calculating maximum length of 2D element
451 MaxElementLength2D_i::MaxElementLength2D_i()
453 myNumericalFunctorPtr.reset( new Controls::MaxElementLength2D() );
454 myFunctorPtr = myNumericalFunctorPtr;
457 FunctorType MaxElementLength2D_i::GetFunctorType()
459 return SMESH::FT_MaxElementLength2D;
463 Class : MaxElementLength3D_i
464 Description : Functor for calculating maximum length of 3D element
466 MaxElementLength3D_i::MaxElementLength3D_i()
468 myNumericalFunctorPtr.reset( new Controls::MaxElementLength3D() );
469 myFunctorPtr = myNumericalFunctorPtr;
472 FunctorType MaxElementLength3D_i::GetFunctorType()
474 return SMESH::FT_MaxElementLength3D;
479 Description : Functor for calculating length off edge
483 myNumericalFunctorPtr.reset( new Controls::Length() );
484 myFunctorPtr = myNumericalFunctorPtr;
487 FunctorType Length_i::GetFunctorType()
489 return SMESH::FT_Length;
494 Description : Functor for calculating length of edge
496 Length2D_i::Length2D_i()
498 myNumericalFunctorPtr.reset( new Controls::Length2D() );
499 myFunctorPtr = myNumericalFunctorPtr;
502 FunctorType Length2D_i::GetFunctorType()
504 return SMESH::FT_Length2D;
507 SMESH::Length2D::Values* Length2D_i::GetValues()
509 SMESH::Controls::Length2D::TValues aValues;
510 (dynamic_cast<SMESH::Controls::Length2D*>(myFunctorPtr.get()))->GetValues( aValues );
512 long i = 0, iEnd = aValues.size();
514 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
515 aResult->length(iEnd);
517 SMESH::Controls::Length2D::TValues::const_iterator anIter;
518 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
520 const SMESH::Controls::Length2D::Value& aVal = *anIter;
521 SMESH::Length2D::Value &aValue = aResult[ i ];
523 aValue.myLength = aVal.myLength;
524 aValue.myPnt1 = aVal.myPntId[ 0 ];
525 aValue.myPnt2 = aVal.myPntId[ 1 ];
528 return aResult._retn();
534 Description : Functor for calculating length of edge
536 Length3D_i::Length3D_i()
538 myNumericalFunctorPtr.reset( new Controls::Length3D() );
539 myFunctorPtr = myNumericalFunctorPtr;
542 FunctorType Length3D_i::GetFunctorType()
544 return SMESH::FT_Length3D;
547 // SMESH::Length3D::Values* Length3D_i::GetValues()
549 // SMESH::Controls::Length3D::TValues aValues;
550 // (dynamic_cast<SMESH::Controls::Length3D*>(myFunctorPtr.get()))->GetValues( aValues );
552 // long i = 0, iEnd = aValues.size();
554 // SMESH::Length3D::Values_var aResult = new SMESH::Length3D::Values(iEnd);
555 // aResult->length(iEnd);
557 // SMESH::Controls::Length3D::TValues::const_iterator anIter;
558 // for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
560 // const SMESH::Controls::Length3D::Value& aVal = *anIter;
561 // SMESH::Length3D::Value &aValue = aResult[ i ];
563 // aValue.myLength = aVal.myLength;
564 // aValue.myPnt1 = aVal.myPntId[ 0 ];
565 // aValue.myPnt2 = aVal.myPntId[ 1 ];
568 // return aResult._retn();
572 Class : Deflection2D_i
573 Description : Functor for calculating distance between a face and geometry
575 Deflection2D_i::Deflection2D_i()
577 myNumericalFunctorPtr.reset( new Controls::Deflection2D() );
578 myFunctorPtr = myNumericalFunctorPtr;
581 FunctorType Deflection2D_i::GetFunctorType()
583 return SMESH::FT_Deflection2D;
587 Class : MultiConnection_i
588 Description : Functor for calculating number of faces conneted to the edge
590 MultiConnection_i::MultiConnection_i()
592 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
593 myFunctorPtr = myNumericalFunctorPtr;
596 FunctorType MultiConnection_i::GetFunctorType()
598 return SMESH::FT_MultiConnection;
602 Class : BallDiameter_i
603 Description : Functor returning diameter of a ball element
605 BallDiameter_i::BallDiameter_i()
607 myNumericalFunctorPtr.reset( new Controls::BallDiameter() );
608 myFunctorPtr = myNumericalFunctorPtr;
611 FunctorType BallDiameter_i::GetFunctorType()
613 return SMESH::FT_BallDiameter;
617 Class : NodeConnectivityNumber_i
618 Description : Functor returning diameter of a ball element
620 NodeConnectivityNumber_i::NodeConnectivityNumber_i()
622 myNumericalFunctorPtr.reset( new Controls::NodeConnectivityNumber() );
623 myFunctorPtr = myNumericalFunctorPtr;
626 FunctorType NodeConnectivityNumber_i::GetFunctorType()
628 return SMESH::FT_NodeConnectivityNumber;
632 Class : MultiConnection2D_i
633 Description : Functor for calculating number of faces conneted to the edge
635 MultiConnection2D_i::MultiConnection2D_i()
637 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
638 myFunctorPtr = myNumericalFunctorPtr;
641 FunctorType MultiConnection2D_i::GetFunctorType()
643 return SMESH::FT_MultiConnection2D;
646 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
648 SMESH::Controls::MultiConnection2D::MValues aValues;
649 (dynamic_cast<SMESH::Controls::MultiConnection2D*>(myFunctorPtr.get()))->GetValues( aValues );
651 long i = 0, iEnd = aValues.size();
653 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
654 aResult->length(iEnd);
656 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
657 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
659 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
660 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
662 aValue.myPnt1 = aVal.myPntId[ 0 ];
663 aValue.myPnt2 = aVal.myPntId[ 1 ];
664 aValue.myNbConnects = (*anIter).second;
667 return aResult._retn();
677 Description : Base class for all predicates
679 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
681 return myPredicatePtr->IsSatisfy( theId );
684 CORBA::Long Predicate_i::NbSatisfying( SMESH::SMESH_IDSource_ptr obj )
686 SMESH::SMESH_Mesh_var meshVar = obj->GetMesh();
687 const SMDS_Mesh* meshDS = MeshPtr2SMDSMesh( meshVar );
690 myPredicatePtr->SetMesh( meshDS );
692 SMDSAbs_ElementType elemType = SMDSAbs_ElementType( GetElementType() );
695 SMDS_ElemIteratorPtr elemIt =
696 SMESH::DownCast<SMESH_Mesh_i*>( meshVar )->GetElements( obj, GetElementType() );
698 while ( elemIt->more() )
700 const SMDS_MeshElement* e = elemIt->next();
701 if ( e && e->GetType() == elemType )
702 nb += myPredicatePtr->IsSatisfy( e->GetID() );
707 Controls::PredicatePtr Predicate_i::GetPredicate()
709 return myPredicatePtr;
713 Class : BadOrientedVolume_i
714 Description : Verify whether a mesh volume is incorrectly oriented from
715 the point of view of MED convention
717 BadOrientedVolume_i::BadOrientedVolume_i()
719 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
720 myFunctorPtr = myPredicatePtr = control;
723 FunctorType BadOrientedVolume_i::GetFunctorType()
725 return SMESH::FT_BadOrientedVolume;
729 Class : BareBorderVolume_i
730 Description : Verify whether a mesh volume has a free facet without a face on it
732 BareBorderVolume_i::BareBorderVolume_i()
734 Controls::PredicatePtr control( new Controls::BareBorderVolume() );
735 myFunctorPtr = myPredicatePtr = control;
738 FunctorType BareBorderVolume_i::GetFunctorType()
740 return SMESH::FT_BareBorderVolume;
744 Class : BareBorderFace_i
745 Description : Verify whether a mesh face has a free border without an edge on it
747 BareBorderFace_i::BareBorderFace_i()
749 Controls::PredicatePtr control( new Controls::BareBorderFace() );
750 myFunctorPtr = myPredicatePtr = control;
753 FunctorType BareBorderFace_i::GetFunctorType()
755 return SMESH::FT_BareBorderFace;
759 Class : OverConstrainedVolume_i
760 Description : Verify whether a mesh volume has only one facet shared with other volumes
762 OverConstrainedVolume_i::OverConstrainedVolume_i()
764 Controls::PredicatePtr control( new Controls::OverConstrainedVolume() );
765 myFunctorPtr = myPredicatePtr = control;
768 FunctorType OverConstrainedVolume_i::GetFunctorType()
770 return SMESH::FT_OverConstrainedVolume;
774 Class : OverConstrainedFace_i
775 Description : Verify whether a mesh face has only one border shared with other faces
777 OverConstrainedFace_i::OverConstrainedFace_i()
779 Controls::PredicatePtr control( new Controls::OverConstrainedFace() );
780 myFunctorPtr = myPredicatePtr = control;
783 FunctorType OverConstrainedFace_i::GetFunctorType()
785 return SMESH::FT_OverConstrainedFace;
789 Class : BelongToMeshGroup_i
790 Description : Verify whether a mesh element is included into a mesh group
792 BelongToMeshGroup_i::BelongToMeshGroup_i()
794 myBelongToMeshGroup = Controls::BelongToMeshGroupPtr( new Controls::BelongToMeshGroup() );
795 myFunctorPtr = myPredicatePtr = myBelongToMeshGroup;
798 BelongToMeshGroup_i::~BelongToMeshGroup_i()
800 SetGroup( SMESH::SMESH_GroupBase::_nil() );
803 void BelongToMeshGroup_i::SetGroup( SMESH::SMESH_GroupBase_ptr theGroup )
805 if ( myGroup->_is_equivalent( theGroup ))
808 if ( ! myGroup->_is_nil() )
809 myGroup->UnRegister();
811 myGroup = SMESH_GroupBase::_duplicate( theGroup );
813 myBelongToMeshGroup->SetGroup( 0 );
814 if ( SMESH_GroupBase_i* gr_i = SMESH::DownCast< SMESH_GroupBase_i* >( myGroup ))
816 myBelongToMeshGroup->SetGroup( gr_i->GetGroupDS() );
821 void BelongToMeshGroup_i::SetGroupID( const char* theID ) // IOR or StoreName
824 if ( strncmp( "IOR:", myID.c_str(), 4 ) == 0 ) // transient mode, no GUI
826 CORBA::Object_var obj = SMESH_Gen_i::GetORB()->string_to_object( myID.c_str() );
827 SetGroup( SMESH::SMESH_GroupBase::_narrow( obj ));
829 else if ( strncmp( "0:", myID.c_str(), 2 ) == 0 ) // transient mode + GUI
831 SALOMEDS::SObject_wrap aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID( myID.c_str() );
832 if ( !aSObj->_is_nil() ) {
833 CORBA::Object_var obj = aSObj->GetObject();
834 SetGroup( SMESH::SMESH_GroupBase::_narrow( obj ));
837 else if ( !myID.empty() ) // persistent mode
839 myBelongToMeshGroup->SetStoreName( myID );
843 std::string BelongToMeshGroup_i::GetGroupID()
845 if ( myGroup->_is_nil() )
846 SMESH::SMESH_GroupBase_var( GetGroup() );
848 if ( !myGroup->_is_nil() )
849 myID = SMESH_Gen_i::GetORB()->object_to_string( myGroup );
854 SMESH::SMESH_GroupBase_ptr BelongToMeshGroup_i::GetGroup()
856 if ( myGroup->_is_nil() && myBelongToMeshGroup->GetGroup() )
858 // search for a group in a current study
859 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
860 if ( StudyContext* sc = aSMESHGen->GetStudyContext() )
866 ior = sc->getIORbyId( id++ );
867 if ( ior.empty() ) break;
868 CORBA::Object_var obj = aSMESHGen->GetORB()->string_to_object( ior.c_str() );
869 if ( SMESH_GroupBase_i* g_i = SMESH::DownCast<SMESH_GroupBase_i*>( obj ))
870 if ( g_i->GetGroupDS() == myBelongToMeshGroup->GetGroup() )
872 SetGroup( g_i->_this() );
878 return SMESH::SMESH_GroupBase::_duplicate( myGroup );
881 FunctorType BelongToMeshGroup_i::GetFunctorType()
883 return SMESH::FT_BelongToMeshGroup;
887 Class : BelongToGeom_i
888 Description : Predicate for selection on geometrical support
890 BelongToGeom_i::BelongToGeom_i()
892 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
893 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
898 BelongToGeom_i::~BelongToGeom_i()
900 CORBA::string_free( myShapeName );
901 CORBA::string_free( myShapeID );
904 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
906 if ( theGeom->_is_nil() )
908 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
909 myBelongToGeomPtr->SetGeom( aLocShape );
910 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
913 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
915 myBelongToGeomPtr->SetGeom( theShape );
918 void BelongToGeom_i::SetElementType(ElementType theType)
920 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
921 TPythonDump()<<this<<".SetElementType("<<theType<<")";
924 FunctorType BelongToGeom_i::GetFunctorType()
926 return SMESH::FT_BelongToGeom;
929 void BelongToGeom_i::SetShapeName( const char* theName )
931 CORBA::string_free( myShapeName );
932 myShapeName = CORBA::string_dup( theName );
933 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
934 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
937 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
939 CORBA::string_free( myShapeName );
940 CORBA::string_free( myShapeID );
941 myShapeName = CORBA::string_dup( theName );
942 myShapeID = CORBA::string_dup( theID );
943 bool hasName = ( theName && theName[0] );
944 bool hasID = ( theID && theID[0] );
947 if ( hasName && hasID )
949 S = getShapeByID( myShapeID );
951 S = getShapeByName( myShapeName );
955 S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
957 myBelongToGeomPtr->SetGeom( S );
960 char* BelongToGeom_i::GetShapeName()
962 return CORBA::string_dup( myShapeName );
965 char* BelongToGeom_i::GetShapeID()
967 return CORBA::string_dup( myShapeID );
970 void BelongToGeom_i::SetTolerance( CORBA::Double theToler )
972 myBelongToGeomPtr->SetTolerance( theToler );
973 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
976 CORBA::Double BelongToGeom_i::GetTolerance()
978 return myBelongToGeomPtr->GetTolerance();
982 Class : BelongToSurface_i
983 Description : Predicate for selection on geometrical support
985 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
987 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
988 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
991 mySurfaceType = theSurfaceType;
994 BelongToSurface_i::~BelongToSurface_i()
996 CORBA::string_free( myShapeName );
997 CORBA::string_free( myShapeID );
1000 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1002 if ( theGeom->_is_nil() )
1004 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1006 if ( aLocShape.ShapeType() == TopAbs_FACE )
1008 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
1009 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
1011 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1016 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
1019 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
1021 CORBA::string_free( myShapeName );
1022 myShapeName = CORBA::string_dup( theName );
1023 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1024 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
1027 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
1029 CORBA::string_free( myShapeName );
1030 CORBA::string_free( myShapeID );
1031 myShapeName = CORBA::string_dup( theName );
1032 myShapeID = CORBA::string_dup( theID );
1033 bool hasName = ( theName && theName[0] );
1034 bool hasID = ( theID && theID[0] );
1037 if ( hasName && hasID )
1039 S = getShapeByID( myShapeID );
1041 S = getShapeByName( myShapeName );
1045 S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
1047 myElementsOnSurfacePtr->SetSurface( S, (SMDSAbs_ElementType)theType );
1050 char* BelongToSurface_i::GetShapeName()
1052 return CORBA::string_dup( myShapeName );
1055 char* BelongToSurface_i::GetShapeID()
1057 return CORBA::string_dup( myShapeID );
1060 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
1062 myElementsOnSurfacePtr->SetTolerance( theToler );
1063 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1066 CORBA::Double BelongToSurface_i::GetTolerance()
1068 return myElementsOnSurfacePtr->GetTolerance();
1071 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
1073 myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
1074 TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
1077 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
1079 return myElementsOnSurfacePtr->GetUseBoundaries();
1084 Class : BelongToPlane_i
1085 Description : Verify whether mesh element lie in pointed Geom planar object
1088 BelongToPlane_i::BelongToPlane_i()
1089 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
1093 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1095 BelongToSurface_i::SetSurface( theGeom, theType );
1096 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
1099 FunctorType BelongToPlane_i::GetFunctorType()
1101 return FT_BelongToPlane;
1105 Class : BelongToCylinder_i
1106 Description : Verify whether mesh element lie in pointed Geom planar object
1109 BelongToCylinder_i::BelongToCylinder_i()
1110 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1114 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1116 BelongToSurface_i::SetSurface( theGeom, theType );
1117 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
1120 FunctorType BelongToCylinder_i::GetFunctorType()
1122 return FT_BelongToCylinder;
1126 Class : BelongToGenSurface_i
1127 Description : Verify whether mesh element lie in pointed Geom planar object
1130 BelongToGenSurface_i::BelongToGenSurface_i()
1131 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1135 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1137 if ( theGeom->_is_nil() )
1139 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1140 if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1141 aLocShape.Nullify();
1143 BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1144 TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1147 FunctorType BelongToGenSurface_i::GetFunctorType()
1149 return FT_BelongToGenSurface;
1153 Class : LyingOnGeom_i
1154 Description : Predicate for selection on geometrical support
1156 LyingOnGeom_i::LyingOnGeom_i()
1158 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1159 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1164 LyingOnGeom_i::~LyingOnGeom_i()
1166 CORBA::string_free( myShapeName );
1167 CORBA::string_free( myShapeID );
1170 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1172 if ( theGeom->_is_nil() )
1174 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1175 myLyingOnGeomPtr->SetGeom( aLocShape );
1176 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1179 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1181 myLyingOnGeomPtr->SetGeom( theShape );
1184 void LyingOnGeom_i::SetElementType(ElementType theType){
1185 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1186 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1189 FunctorType LyingOnGeom_i::GetFunctorType()
1191 return SMESH::FT_LyingOnGeom;
1194 void LyingOnGeom_i::SetShapeName( const char* theName )
1196 CORBA::string_free( myShapeName );
1197 myShapeName = CORBA::string_dup( theName );
1198 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1199 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1202 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1204 CORBA::string_free( myShapeName );
1205 CORBA::string_free( myShapeID );
1206 myShapeName = CORBA::string_dup( theName );
1207 myShapeID = CORBA::string_dup( theID );
1208 bool hasName = ( theName && theName[0] );
1209 bool hasID = ( theID && theID[0] );
1212 if ( hasName && hasID )
1214 S = getShapeByID( myShapeID );
1216 S = getShapeByName( myShapeName );
1220 S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
1222 myLyingOnGeomPtr->SetGeom( S );
1225 char* LyingOnGeom_i::GetShapeName()
1227 return CORBA::string_dup( myShapeName );
1230 char* LyingOnGeom_i::GetShapeID()
1232 return CORBA::string_dup( myShapeID );
1235 void LyingOnGeom_i::SetTolerance( CORBA::Double theToler )
1237 myLyingOnGeomPtr->SetTolerance( theToler );
1238 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1241 CORBA::Double LyingOnGeom_i::GetTolerance()
1243 return myLyingOnGeomPtr->GetTolerance();
1247 Class : FreeBorders_i
1248 Description : Predicate for free borders
1250 FreeBorders_i::FreeBorders_i()
1252 myPredicatePtr.reset(new Controls::FreeBorders());
1253 myFunctorPtr = myPredicatePtr;
1256 FunctorType FreeBorders_i::GetFunctorType()
1258 return SMESH::FT_FreeBorders;
1263 Description : Predicate for free borders
1265 FreeEdges_i::FreeEdges_i()
1266 : myFreeEdgesPtr( new Controls::FreeEdges() )
1268 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1271 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1273 SMESH::Controls::FreeEdges::TBorders aBorders;
1274 myFreeEdgesPtr->GetBoreders( aBorders );
1276 long i = 0, iEnd = aBorders.size();
1278 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1279 aResult->length(iEnd);
1281 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1282 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1284 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1285 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1287 aBorder.myElemId = aBord.myElemId;
1288 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1289 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1291 return aResult._retn();
1294 FunctorType FreeEdges_i::GetFunctorType()
1296 return SMESH::FT_FreeEdges;
1301 Description : Predicate for free faces
1303 FreeFaces_i::FreeFaces_i()
1305 myPredicatePtr.reset(new Controls::FreeFaces());
1306 myFunctorPtr = myPredicatePtr;
1309 FunctorType FreeFaces_i::GetFunctorType()
1311 return SMESH::FT_FreeFaces;
1316 Description : Predicate for free nodes
1318 FreeNodes_i::FreeNodes_i()
1320 myPredicatePtr.reset(new Controls::FreeNodes());
1321 myFunctorPtr = myPredicatePtr;
1324 FunctorType FreeNodes_i::GetFunctorType()
1326 return SMESH::FT_FreeNodes;
1330 Class : EqualNodes_i
1331 Description : Predicate for Equal nodes
1333 EqualNodes_i::EqualNodes_i()
1335 myCoincidentNodesPtr.reset(new Controls::CoincidentNodes());
1336 myFunctorPtr = myPredicatePtr = myCoincidentNodesPtr;
1339 FunctorType EqualNodes_i::GetFunctorType()
1341 return SMESH::FT_EqualNodes;
1344 void EqualNodes_i::SetTolerance( double tol )
1346 myCoincidentNodesPtr->SetTolerance( tol );
1349 double EqualNodes_i::GetTolerance()
1351 return myCoincidentNodesPtr->GetTolerance();
1355 Class : EqualEdges_i
1356 Description : Predicate for Equal Edges
1358 EqualEdges_i::EqualEdges_i()
1360 myPredicatePtr.reset(new Controls::CoincidentElements1D());
1361 myFunctorPtr = myPredicatePtr;
1364 FunctorType EqualEdges_i::GetFunctorType()
1366 return SMESH::FT_EqualEdges;
1370 Class : EqualFaces_i
1371 Description : Predicate for Equal Faces
1373 EqualFaces_i::EqualFaces_i()
1375 myPredicatePtr.reset(new Controls::CoincidentElements2D());
1376 myFunctorPtr = myPredicatePtr;
1379 FunctorType EqualFaces_i::GetFunctorType()
1381 return SMESH::FT_EqualFaces;
1385 Class : EqualVolumes_i
1386 Description : Predicate for Equal Volumes
1388 EqualVolumes_i::EqualVolumes_i()
1390 myPredicatePtr.reset(new Controls::CoincidentElements3D());
1391 myFunctorPtr = myPredicatePtr;
1394 FunctorType EqualVolumes_i::GetFunctorType()
1396 return SMESH::FT_EqualVolumes;
1401 Class : RangeOfIds_i
1402 Description : Predicate for Range of Ids.
1403 Range may be specified with two ways.
1404 1. Using AddToRange method
1405 2. With SetRangeStr method. Parameter of this method is a string
1406 like as "1,2,3,50-60,63,67,70-"
1409 RangeOfIds_i::RangeOfIds_i()
1411 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1412 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1415 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1417 CORBA::Long iEnd = theIds.length();
1418 for ( CORBA::Long i = 0; i < iEnd; i++ )
1419 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1420 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1423 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1425 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1426 return myRangeOfIdsPtr->SetRangeStr(
1427 TCollection_AsciiString( (Standard_CString)theRange ) );
1430 char* RangeOfIds_i::GetRangeStr()
1432 TCollection_AsciiString aStr;
1433 myRangeOfIdsPtr->GetRangeStr( aStr );
1434 return CORBA::string_dup( aStr.ToCString() );
1437 void RangeOfIds_i::SetElementType( ElementType theType )
1439 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1440 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1443 FunctorType RangeOfIds_i::GetFunctorType()
1445 return SMESH::FT_RangeOfIds;
1449 Class : LinearOrQuadratic_i
1450 Description : Predicate to verify whether a mesh element is linear
1452 LinearOrQuadratic_i::LinearOrQuadratic_i()
1454 myLinearOrQuadraticPtr.reset(new Controls::LinearOrQuadratic());
1455 myFunctorPtr = myPredicatePtr = myLinearOrQuadraticPtr;
1458 void LinearOrQuadratic_i::SetElementType(ElementType theType)
1460 myLinearOrQuadraticPtr->SetType(SMDSAbs_ElementType(theType));
1461 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1464 FunctorType LinearOrQuadratic_i::GetFunctorType()
1466 return SMESH::FT_LinearOrQuadratic;
1470 Class : GroupColor_i
1471 Description : Functor for check color of group to which mesh element belongs to
1473 GroupColor_i::GroupColor_i()
1475 myGroupColorPtr.reset(new Controls::GroupColor());
1476 myFunctorPtr = myPredicatePtr = myGroupColorPtr;
1479 FunctorType GroupColor_i::GetFunctorType()
1481 return SMESH::FT_GroupColor;
1484 void GroupColor_i::SetColorStr( const char* theColor )
1486 myGroupColorPtr->SetColorStr(
1487 TCollection_AsciiString( (Standard_CString)theColor ) );
1488 TPythonDump()<<this<<".SetColorStr('"<<theColor<<"')";
1491 char* GroupColor_i::GetColorStr()
1493 TCollection_AsciiString aStr;
1494 myGroupColorPtr->GetColorStr( aStr );
1495 return CORBA::string_dup( aStr.ToCString() );
1498 void GroupColor_i::SetElementType(ElementType theType)
1500 myGroupColorPtr->SetType(SMDSAbs_ElementType(theType));
1501 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1505 Class : ElemGeomType_i
1506 Description : Predicate check is element has indicated geometry type
1508 ElemGeomType_i::ElemGeomType_i()
1510 myElemGeomTypePtr.reset(new Controls::ElemGeomType());
1511 myFunctorPtr = myPredicatePtr = myElemGeomTypePtr;
1514 void ElemGeomType_i::SetElementType(ElementType theType)
1516 myElemGeomTypePtr->SetType(SMDSAbs_ElementType(theType));
1517 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1520 void ElemGeomType_i::SetGeometryType(GeometryType theType)
1522 myElemGeomTypePtr->SetGeomType(SMDSAbs_GeometryType(theType));
1523 TPythonDump()<<this<<".SetGeometryType("<<theType<<")";
1526 GeometryType ElemGeomType_i::GetGeometryType() const
1528 return (GeometryType)myElemGeomTypePtr->GetGeomType();
1531 FunctorType ElemGeomType_i::GetFunctorType()
1533 return SMESH::FT_ElemGeomType;
1537 Class : ElemEntityType_i
1538 Description : Predicate check is element has indicated entity type
1540 ElemEntityType_i::ElemEntityType_i()
1542 myElemEntityTypePtr.reset(new Controls::ElemEntityType());
1543 myFunctorPtr = myPredicatePtr = myElemEntityTypePtr;
1546 void ElemEntityType_i::SetElementType(ElementType theType)
1548 myElemEntityTypePtr->SetType(SMDSAbs_ElementType(theType));
1549 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1552 void ElemEntityType_i::SetEntityType(EntityType theEntityType)
1554 myElemEntityTypePtr->SetElemEntityType(SMDSAbs_EntityType (theEntityType));
1555 TPythonDump()<<this<<".SetEntityType("<<theEntityType<<")";
1557 EntityType ElemEntityType_i::GetEntityType() const
1559 return (EntityType) myElemEntityTypePtr->GetElemEntityType();
1562 FunctorType ElemEntityType_i::GetFunctorType()
1564 return SMESH::FT_EntityType;
1568 Class : CoplanarFaces_i
1569 Description : Returns true if a mesh face is a coplanar neighbour to a given one
1571 CoplanarFaces_i::CoplanarFaces_i()
1573 myCoplanarFacesPtr.reset(new Controls::CoplanarFaces());
1574 myFunctorPtr = myPredicatePtr = myCoplanarFacesPtr;
1577 void CoplanarFaces_i::SetFace ( CORBA::Long theFaceID )
1579 myCoplanarFacesPtr->SetFace(theFaceID);
1580 TPythonDump()<<this<<".SetFace("<<theFaceID<<")";
1583 void CoplanarFaces_i::SetTolerance( CORBA::Double theToler )
1585 myCoplanarFacesPtr->SetTolerance(theToler);
1586 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1589 CORBA::Long CoplanarFaces_i::GetFace () const
1591 return myCoplanarFacesPtr->GetFace();
1594 char* CoplanarFaces_i::GetFaceAsString () const
1596 TCollection_AsciiString str(Standard_Integer(myCoplanarFacesPtr->GetFace()));
1597 return CORBA::string_dup( str.ToCString() );
1600 CORBA::Double CoplanarFaces_i::GetTolerance() const
1602 return myCoplanarFacesPtr->GetTolerance();
1605 FunctorType CoplanarFaces_i::GetFunctorType()
1607 return SMESH::FT_CoplanarFaces;
1611 * Class : ConnectedElements_i
1612 * Description : Returns true if an element is connected via other elements to the element
1613 * located at a given point.
1615 ConnectedElements_i::ConnectedElements_i()
1617 myConnectedElementsPtr.reset(new Controls::ConnectedElements());
1618 myFunctorPtr = myPredicatePtr = myConnectedElementsPtr;
1621 FunctorType ConnectedElements_i::GetFunctorType()
1623 return FT_ConnectedElements;
1626 void ConnectedElements_i::SetElementType( ElementType theType )
1628 myConnectedElementsPtr->SetType( SMDSAbs_ElementType( theType ));
1629 TPythonDump() << this << ".SetElementType( " << theType << " )";
1632 void ConnectedElements_i::SetPoint( CORBA::Double x, CORBA::Double y, CORBA::Double z )
1634 myConnectedElementsPtr->SetPoint( x,y,z );
1636 TPythonDump() << this << ".SetPoint( " << x << ", " << y << ", " << z << " )";
1639 void ConnectedElements_i::SetVertex( GEOM::GEOM_Object_ptr vertex )
1640 throw (SALOME::SALOME_Exception)
1642 TopoDS_Shape shape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( vertex );
1643 if ( shape.IsNull() )
1644 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetVertex(): NULL Vertex",
1645 SALOME::BAD_PARAM );
1647 TopExp_Explorer v( shape, TopAbs_VERTEX );
1649 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetVertex(): empty vertex",
1650 SALOME::BAD_PARAM );
1652 gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( v.Current() ));
1653 myConnectedElementsPtr->SetPoint( p.X(), p.Y(), p.Z() );
1655 CORBA::String_var id = vertex->GetStudyEntry();
1656 myVertexID = id.in();
1658 TPythonDump() << this << ".SetVertex( " << vertex << " )";
1661 void ConnectedElements_i::SetNode ( CORBA::Long nodeID )
1662 throw (SALOME::SALOME_Exception)
1665 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetNode(): nodeID must be > 0",
1666 SALOME::BAD_PARAM );
1668 myConnectedElementsPtr->SetNode( nodeID );
1670 TPythonDump() << this << ".SetNode( " << nodeID << " )";
1674 * \brief This is a comfort method for Filter dialog
1676 void ConnectedElements_i::SetThreshold ( const char* threshold,
1677 SMESH::ConnectedElements::ThresholdType type )
1678 throw (SALOME::SALOME_Exception)
1681 THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetThreshold(): NULL threshold",
1682 SALOME::BAD_PARAM );
1685 case SMESH::ConnectedElements::POINT: // read 3 node coordinates ///////////////////
1687 std::vector< double > xyz;
1692 while ( *threshold &&
1693 *threshold != '+' &&
1694 *threshold != '-' &&
1695 !isdigit( *threshold ))
1699 // read a coordinate
1700 xyz.push_back( strtod( threshold, &endptr ));
1701 if ( threshold == endptr )
1703 xyz.resize( xyz.size() - 1 );
1708 while ( xyz.size() < 3 );
1710 if ( xyz.size() < 3 )
1711 THROW_SALOME_CORBA_EXCEPTION
1712 ( "ConnectedElements_i::SetThreshold(): invalid point coordinates", SALOME::BAD_PARAM );
1714 SetPoint( xyz[0], xyz[1], xyz[2] );
1717 case SMESH::ConnectedElements::VERTEX: // get a VERTEX by its entry /////////////////
1719 SALOMEDS::SObject_wrap sobj = SMESH_Gen_i::getStudyServant()->FindObjectID( threshold );
1720 if ( sobj->_is_nil() )
1721 THROW_SALOME_CORBA_EXCEPTION
1722 ( "ConnectedElements_i::SetThreshold(): invalid vertex study entry", SALOME::BAD_PARAM );
1723 CORBA::Object_var obj = sobj->GetObject();
1724 GEOM::GEOM_Object_var vertex = GEOM::GEOM_Object::_narrow( obj );
1725 if ( vertex->_is_nil() )
1726 THROW_SALOME_CORBA_EXCEPTION
1727 ( "ConnectedElements_i::SetThreshold(): no GEOM_Object in SObject", SALOME::BAD_PARAM );
1728 SetVertex( vertex );
1731 case SMESH::ConnectedElements::NODE: // read a node ID ////////////////////////////
1734 int id = strtol( threshold, &endptr, 10 );
1735 if ( threshold == endptr )
1736 THROW_SALOME_CORBA_EXCEPTION
1737 ( "ConnectedElements_i::SetThreshold(): invalid node ID", SALOME::BAD_PARAM );
1742 THROW_SALOME_CORBA_EXCEPTION
1743 ( "ConnectedElements_i::SetThreshold(): invalid ThresholdType", SALOME::BAD_PARAM );
1747 char* ConnectedElements_i::GetThreshold ( SMESH::ConnectedElements::ThresholdType& type )
1749 std::string threshold;
1750 if ( !myVertexID.empty() )
1752 threshold = myVertexID;
1753 type = SMESH::ConnectedElements::VERTEX;
1757 std::vector<double> xyz = myConnectedElementsPtr->GetPoint();
1758 if ( xyz.size() == 3 )
1760 threshold = SMESH_Comment( xyz[0] ) << "; " << xyz[1] << "; " << xyz[2];
1761 type = SMESH::ConnectedElements::POINT;
1765 threshold = SMESH_Comment( myConnectedElementsPtr->GetNode() );
1766 type = SMESH::ConnectedElements::NODE;
1769 return CORBA::string_dup( threshold.c_str() );
1773 Class : Comparator_i
1774 Description : Base class for comparators
1776 Comparator_i::Comparator_i():
1777 myNumericalFunctor( NULL )
1780 Comparator_i::~Comparator_i()
1782 if ( myNumericalFunctor )
1783 myNumericalFunctor->UnRegister();
1786 void Comparator_i::SetMargin( CORBA::Double theValue )
1788 myComparatorPtr->SetMargin( theValue );
1789 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1792 CORBA::Double Comparator_i::GetMargin()
1794 return myComparatorPtr->GetMargin();
1797 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1799 if ( myNumericalFunctor )
1800 myNumericalFunctor->UnRegister();
1802 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1804 if ( myNumericalFunctor )
1806 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1807 myNumericalFunctor->Register();
1808 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1812 Controls::ComparatorPtr Comparator_i::GetComparator()
1814 return myComparatorPtr;
1817 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1819 return myNumericalFunctor;
1825 Description : Comparator "<"
1827 LessThan_i::LessThan_i()
1829 myComparatorPtr.reset( new Controls::LessThan() );
1830 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1833 FunctorType LessThan_i::GetFunctorType()
1835 return SMESH::FT_LessThan;
1841 Description : Comparator ">"
1843 MoreThan_i::MoreThan_i()
1845 myComparatorPtr.reset( new Controls::MoreThan() );
1846 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1849 FunctorType MoreThan_i::GetFunctorType()
1851 return SMESH::FT_MoreThan;
1857 Description : Comparator "="
1859 EqualTo_i::EqualTo_i()
1860 : myEqualToPtr( new Controls::EqualTo() )
1862 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1865 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1867 myEqualToPtr->SetTolerance( theToler );
1868 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1871 CORBA::Double EqualTo_i::GetTolerance()
1873 return myEqualToPtr->GetTolerance();
1876 FunctorType EqualTo_i::GetFunctorType()
1878 return SMESH::FT_EqualTo;
1882 Class : LogicalNOT_i
1883 Description : Logical NOT predicate
1885 LogicalNOT_i::LogicalNOT_i():
1886 myLogicalNOTPtr( new Controls::LogicalNOT() ),
1889 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1892 LogicalNOT_i::~LogicalNOT_i()
1895 myPredicate->UnRegister();
1898 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1901 myPredicate->UnRegister();
1903 myPredicate = SMESH::GetPredicate(thePredicate);
1906 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1907 myPredicate->Register();
1908 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1912 FunctorType LogicalNOT_i::GetFunctorType()
1914 return SMESH::FT_LogicalNOT;
1917 Predicate_i* LogicalNOT_i::GetPredicate_i()
1925 Class : LogicalBinary_i
1926 Description : Base class for binary logical predicate
1928 LogicalBinary_i::LogicalBinary_i()
1929 : myPredicate1( NULL ),
1930 myPredicate2( NULL )
1933 LogicalBinary_i::~LogicalBinary_i()
1936 myPredicate1->UnRegister();
1939 myPredicate2->UnRegister();
1942 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1945 myPredicate1->SetMesh( theMesh );
1948 myPredicate2->SetMesh( theMesh );
1951 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1954 myPredicate1->UnRegister();
1956 myPredicate1 = SMESH::GetPredicate(thePredicate);
1958 if ( myPredicate1 ){
1959 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1960 myPredicate1->Register();
1961 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1965 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1968 myPredicate2->UnRegister();
1970 myPredicate2 = SMESH::GetPredicate(thePredicate);
1972 if ( myPredicate2 ){
1973 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1974 myPredicate2->Register();
1975 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1979 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1981 return myLogicalBinaryPtr;
1984 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1986 return myPredicate1;
1988 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1990 return myPredicate2;
1995 Class : LogicalAND_i
1996 Description : Logical AND
1998 LogicalAND_i::LogicalAND_i()
2000 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
2001 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
2004 FunctorType LogicalAND_i::GetFunctorType()
2006 return SMESH::FT_LogicalAND;
2012 Description : Logical OR
2014 LogicalOR_i::LogicalOR_i()
2016 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
2017 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
2020 FunctorType LogicalOR_i::GetFunctorType()
2022 return SMESH::FT_LogicalOR;
2030 FilterManager_i::FilterManager_i()
2031 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
2033 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
2034 //PortableServer::ObjectId_var anObjectId =
2035 // SMESH_Gen_i::GetPOA()->activate_object( this );
2039 FilterManager_i::~FilterManager_i()
2041 //TPythonDump()<<this<<".UnRegister()";
2045 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
2047 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
2048 SMESH::MinimumAngle_var anObj = aServant->_this();
2049 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
2050 return anObj._retn();
2054 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
2056 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
2057 SMESH::AspectRatio_var anObj = aServant->_this();
2058 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
2059 return anObj._retn();
2063 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
2065 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
2066 SMESH::AspectRatio3D_var anObj = aServant->_this();
2067 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
2068 return anObj._retn();
2072 Warping_ptr FilterManager_i::CreateWarping()
2074 SMESH::Warping_i* aServant = new SMESH::Warping_i();
2075 SMESH::Warping_var anObj = aServant->_this();
2076 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
2077 return anObj._retn();
2081 Taper_ptr FilterManager_i::CreateTaper()
2083 SMESH::Taper_i* aServant = new SMESH::Taper_i();
2084 SMESH::Taper_var anObj = aServant->_this();
2085 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
2086 return anObj._retn();
2090 Skew_ptr FilterManager_i::CreateSkew()
2092 SMESH::Skew_i* aServant = new SMESH::Skew_i();
2093 SMESH::Skew_var anObj = aServant->_this();
2094 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
2095 return anObj._retn();
2099 Area_ptr FilterManager_i::CreateArea()
2101 SMESH::Area_i* aServant = new SMESH::Area_i();
2102 SMESH::Area_var anObj = aServant->_this();
2103 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
2104 return anObj._retn();
2108 Volume3D_ptr FilterManager_i::CreateVolume3D()
2110 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
2111 SMESH::Volume3D_var anObj = aServant->_this();
2112 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
2113 return anObj._retn();
2117 MaxElementLength2D_ptr FilterManager_i::CreateMaxElementLength2D()
2119 SMESH::MaxElementLength2D_i* aServant = new SMESH::MaxElementLength2D_i();
2120 SMESH::MaxElementLength2D_var anObj = aServant->_this();
2121 TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength2D()";
2122 return anObj._retn();
2126 MaxElementLength3D_ptr FilterManager_i::CreateMaxElementLength3D()
2128 SMESH::MaxElementLength3D_i* aServant = new SMESH::MaxElementLength3D_i();
2129 SMESH::MaxElementLength3D_var anObj = aServant->_this();
2130 TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength3D()";
2131 return anObj._retn();
2135 Length_ptr FilterManager_i::CreateLength()
2137 SMESH::Length_i* aServant = new SMESH::Length_i();
2138 SMESH::Length_var anObj = aServant->_this();
2139 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
2140 return anObj._retn();
2143 Length2D_ptr FilterManager_i::CreateLength2D()
2145 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
2146 SMESH::Length2D_var anObj = aServant->_this();
2147 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
2148 return anObj._retn();
2151 Length3D_ptr FilterManager_i::CreateLength3D()
2153 SMESH::Length3D_i* aServant = new SMESH::Length3D_i();
2154 SMESH::Length3D_var anObj = aServant->_this();
2155 TPythonDump()<<aServant<<" = "<<this<<".CreateLength3D()";
2156 return anObj._retn();
2159 Deflection2D_ptr FilterManager_i::CreateDeflection2D()
2161 SMESH::Deflection2D_i* aServant = new SMESH::Deflection2D_i();
2162 SMESH::Deflection2D_var anObj = aServant->_this();
2163 TPythonDump()<<aServant<<" = "<<this<<".CreateDeflection2D()";
2164 return anObj._retn();
2167 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
2169 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
2170 SMESH::MultiConnection_var anObj = aServant->_this();
2171 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
2172 return anObj._retn();
2175 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
2177 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
2178 SMESH::MultiConnection2D_var anObj = aServant->_this();
2179 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
2180 return anObj._retn();
2183 BallDiameter_ptr FilterManager_i::CreateBallDiameter()
2185 SMESH::BallDiameter_i* aServant = new SMESH::BallDiameter_i();
2186 SMESH::BallDiameter_var anObj = aServant->_this();
2187 TPythonDump()<<aServant<<" = "<<this<<".CreateBallDiameter()";
2188 return anObj._retn();
2191 NodeConnectivityNumber_ptr FilterManager_i::CreateNodeConnectivityNumber()
2193 SMESH::NodeConnectivityNumber_i* aServant = new SMESH::NodeConnectivityNumber_i();
2194 SMESH::NodeConnectivityNumber_var anObj = aServant->_this();
2195 TPythonDump()<<aServant<<" = "<<this<<".CreateNodeConnectivityNumber()";
2196 return anObj._retn();
2199 BelongToMeshGroup_ptr FilterManager_i::CreateBelongToMeshGroup()
2201 SMESH::BelongToMeshGroup_i* aServant = new SMESH::BelongToMeshGroup_i();
2202 SMESH::BelongToMeshGroup_var anObj = aServant->_this();
2203 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToMeshGroup()";
2204 return anObj._retn();
2207 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
2209 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
2210 SMESH::BelongToGeom_var anObj = aServant->_this();
2211 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
2212 return anObj._retn();
2215 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
2217 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
2218 SMESH::BelongToPlane_var anObj = aServant->_this();
2219 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
2220 return anObj._retn();
2223 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
2225 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
2226 SMESH::BelongToCylinder_var anObj = aServant->_this();
2227 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
2228 return anObj._retn();
2231 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
2233 SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
2234 SMESH::BelongToGenSurface_var anObj = aServant->_this();
2235 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
2236 return anObj._retn();
2239 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
2241 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
2242 SMESH::LyingOnGeom_var anObj = aServant->_this();
2243 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
2244 return anObj._retn();
2247 CoplanarFaces_ptr FilterManager_i::CreateCoplanarFaces()
2249 SMESH::CoplanarFaces_i* aServant = new SMESH::CoplanarFaces_i();
2250 SMESH::CoplanarFaces_var anObj = aServant->_this();
2251 TPythonDump()<<aServant<<" = "<<this<<".CreateCoplanarFaces()";
2252 return anObj._retn();
2255 ConnectedElements_ptr FilterManager_i::CreateConnectedElements()
2257 SMESH::ConnectedElements_i* aServant = new SMESH::ConnectedElements_i();
2258 SMESH::ConnectedElements_var anObj = aServant->_this();
2259 TPythonDump()<<aServant<<" = "<<this<<".CreateConnectedElements()";
2260 return anObj._retn();
2263 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
2265 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
2266 SMESH::FreeBorders_var anObj = aServant->_this();
2267 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
2268 return anObj._retn();
2271 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
2273 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
2274 SMESH::FreeEdges_var anObj = aServant->_this();
2275 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
2276 return anObj._retn();
2279 FreeFaces_ptr FilterManager_i::CreateFreeFaces()
2281 SMESH::FreeFaces_i* aServant = new SMESH::FreeFaces_i();
2282 SMESH::FreeFaces_var anObj = aServant->_this();
2283 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeFaces()";
2284 return anObj._retn();
2287 FreeNodes_ptr FilterManager_i::CreateFreeNodes()
2289 SMESH::FreeNodes_i* aServant = new SMESH::FreeNodes_i();
2290 SMESH::FreeNodes_var anObj = aServant->_this();
2291 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeNodes()";
2292 return anObj._retn();
2295 EqualNodes_ptr FilterManager_i::CreateEqualNodes()
2297 SMESH::EqualNodes_i* aServant = new SMESH::EqualNodes_i();
2298 SMESH::EqualNodes_var anObj = aServant->_this();
2299 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualNodes()";
2300 return anObj._retn();
2303 EqualEdges_ptr FilterManager_i::CreateEqualEdges()
2305 SMESH::EqualEdges_i* aServant = new SMESH::EqualEdges_i();
2306 SMESH::EqualEdges_var anObj = aServant->_this();
2307 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualEdges()";
2308 return anObj._retn();
2310 EqualFaces_ptr FilterManager_i::CreateEqualFaces()
2312 SMESH::EqualFaces_i* aServant = new SMESH::EqualFaces_i();
2313 SMESH::EqualFaces_var anObj = aServant->_this();
2314 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualFaces()";
2315 return anObj._retn();
2317 EqualVolumes_ptr FilterManager_i::CreateEqualVolumes()
2319 SMESH::EqualVolumes_i* aServant = new SMESH::EqualVolumes_i();
2320 SMESH::EqualVolumes_var anObj = aServant->_this();
2321 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualVolumes()";
2322 return anObj._retn();
2325 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
2327 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
2328 SMESH::RangeOfIds_var anObj = aServant->_this();
2329 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
2330 return anObj._retn();
2333 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
2335 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
2336 SMESH::BadOrientedVolume_var anObj = aServant->_this();
2337 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
2338 return anObj._retn();
2341 BareBorderVolume_ptr FilterManager_i::CreateBareBorderVolume()
2343 SMESH::BareBorderVolume_i* aServant = new SMESH::BareBorderVolume_i();
2344 SMESH::BareBorderVolume_var anObj = aServant->_this();
2345 TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderVolume()";
2346 return anObj._retn();
2349 BareBorderFace_ptr FilterManager_i::CreateBareBorderFace()
2351 SMESH::BareBorderFace_i* aServant = new SMESH::BareBorderFace_i();
2352 SMESH::BareBorderFace_var anObj = aServant->_this();
2353 TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderFace()";
2354 return anObj._retn();
2357 OverConstrainedVolume_ptr FilterManager_i::CreateOverConstrainedVolume()
2359 SMESH::OverConstrainedVolume_i* aServant = new SMESH::OverConstrainedVolume_i();
2360 SMESH::OverConstrainedVolume_var anObj = aServant->_this();
2361 TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedVolume()";
2362 return anObj._retn();
2365 OverConstrainedFace_ptr FilterManager_i::CreateOverConstrainedFace()
2367 SMESH::OverConstrainedFace_i* aServant = new SMESH::OverConstrainedFace_i();
2368 SMESH::OverConstrainedFace_var anObj = aServant->_this();
2369 TPythonDump()<<aServant<<" = "<<this<<".CreateOverConstrainedFace()";
2370 return anObj._retn();
2373 LessThan_ptr FilterManager_i::CreateLessThan()
2375 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
2376 SMESH::LessThan_var anObj = aServant->_this();
2377 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
2378 return anObj._retn();
2381 MoreThan_ptr FilterManager_i::CreateMoreThan()
2383 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
2384 SMESH::MoreThan_var anObj = aServant->_this();
2385 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
2386 return anObj._retn();
2389 EqualTo_ptr FilterManager_i::CreateEqualTo()
2391 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
2392 SMESH::EqualTo_var anObj = aServant->_this();
2393 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
2394 return anObj._retn();
2397 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
2399 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
2400 SMESH::LogicalNOT_var anObj = aServant->_this();
2401 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
2402 return anObj._retn();
2405 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
2407 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
2408 SMESH::LogicalAND_var anObj = aServant->_this();
2409 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
2410 return anObj._retn();
2413 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
2415 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
2416 SMESH::LogicalOR_var anObj = aServant->_this();
2417 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
2418 return anObj._retn();
2421 LinearOrQuadratic_ptr FilterManager_i::CreateLinearOrQuadratic()
2423 SMESH::LinearOrQuadratic_i* aServant = new SMESH::LinearOrQuadratic_i();
2424 SMESH::LinearOrQuadratic_var anObj = aServant->_this();
2425 TPythonDump()<<aServant<<" = "<<this<<".CreateLinearOrQuadratic()";
2426 return anObj._retn();
2429 GroupColor_ptr FilterManager_i::CreateGroupColor()
2431 SMESH::GroupColor_i* aServant = new SMESH::GroupColor_i();
2432 SMESH::GroupColor_var anObj = aServant->_this();
2433 TPythonDump()<<aServant<<" = "<<this<<".CreateGroupColor()";
2434 return anObj._retn();
2437 ElemGeomType_ptr FilterManager_i::CreateElemGeomType()
2439 SMESH::ElemGeomType_i* aServant = new SMESH::ElemGeomType_i();
2440 SMESH::ElemGeomType_var anObj = aServant->_this();
2441 TPythonDump()<<aServant<<" = "<<this<<".CreateElemGeomType()";
2442 return anObj._retn();
2445 ElemEntityType_ptr FilterManager_i::CreateElemEntityType()
2447 SMESH::ElemEntityType_i* aServant = new SMESH::ElemEntityType_i();
2448 SMESH::ElemEntityType_var anObj = aServant->_this();
2449 TPythonDump()<<aServant<<" = "<<this<<".CreateElemEntityType()";
2450 return anObj._retn();
2453 Filter_ptr FilterManager_i::CreateFilter()
2455 SMESH::Filter_i* aServant = new SMESH::Filter_i();
2456 SMESH::Filter_var anObj = aServant->_this();
2457 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
2458 return anObj._retn();
2461 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
2463 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
2464 SMESH::FilterLibrary_var anObj = aServant->_this();
2465 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary('"<<aFileName<<"')";
2466 return anObj._retn();
2469 FilterLibrary_ptr FilterManager_i::CreateLibrary()
2471 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
2472 SMESH::FilterLibrary_var anObj = aServant->_this();
2473 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
2474 return anObj._retn();
2477 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
2479 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
2480 return remove( aFileName ) ? false : true;
2483 //=============================================================================
2485 * SMESH_Gen_i::CreateFilterManager
2487 * Create filter manager
2489 //=============================================================================
2491 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
2493 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2494 SMESH::FilterManager_var anObj = aFilter->_this();
2495 return anObj._retn();
2503 //=======================================================================
2504 // name : Filter_i::Filter_i
2505 // Purpose : Constructor
2506 //=======================================================================
2507 Filter_i::Filter_i()
2508 : myPredicate( NULL )
2511 //=======================================================================
2512 // name : Filter_i::~Filter_i
2513 // Purpose : Destructor
2514 //=======================================================================
2515 Filter_i::~Filter_i()
2518 myPredicate->UnRegister();
2520 if(!CORBA::is_nil(myMesh))
2521 myMesh->UnRegister();
2527 //=======================================================================
2528 // name : Filter_i::SetPredicate
2529 // Purpose : Set predicate
2530 //=======================================================================
2531 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
2534 myPredicate->UnRegister();
2536 myPredicate = SMESH::GetPredicate(thePredicate);
2540 myFilter.SetPredicate( myPredicate->GetPredicate() );
2541 myPredicate->Register();
2542 if ( const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh))
2543 myPredicate->GetPredicate()->SetMesh( aMesh );
2544 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
2546 NotifyerAndWaiter::Modified();
2549 //=======================================================================
2550 // name : Filter_i::GetElementType
2551 // Purpose : Get entity type
2552 //=======================================================================
2553 SMESH::ElementType Filter_i::GetElementType()
2555 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
2558 //=======================================================================
2559 // name : Filter_i::SetMesh
2560 // Purpose : Set mesh
2561 //=======================================================================
2564 SetMesh( SMESH_Mesh_ptr theMesh )
2566 if(!CORBA::is_nil(theMesh))
2567 theMesh->Register();
2569 if(!CORBA::is_nil(myMesh))
2570 myMesh->UnRegister();
2572 myMesh = SMESH_Mesh::_duplicate( theMesh );
2573 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
2576 if ( const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2577 myPredicate->GetPredicate()->SetMesh( aMesh );
2584 return GetElementsId(myMesh);
2587 //=======================================================================
2588 // name : Filter_i::GetElementsId
2589 // Purpose : Get ids of entities
2590 //=======================================================================
2593 GetElementsId( Predicate_i* thePredicate,
2594 const SMDS_Mesh* theMesh,
2595 Controls::Filter::TIdSequence& theSequence )
2598 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
2603 GetElementsId( Predicate_i* thePredicate,
2604 SMESH_Mesh_ptr theMesh,
2605 Controls::Filter::TIdSequence& theSequence )
2608 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2609 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
2614 GetElementsId( SMESH_Mesh_ptr theMesh )
2616 SMESH::long_array_var anArray = new SMESH::long_array;
2617 if(!CORBA::is_nil(theMesh) && myPredicate){
2619 Controls::Filter::TIdSequence aSequence;
2620 GetElementsId(myPredicate,theMesh,aSequence);
2621 long i = 0, iEnd = aSequence.size();
2622 anArray->length( iEnd );
2623 for ( ; i < iEnd; i++ )
2624 anArray[ i ] = aSequence[i];
2626 return anArray._retn();
2631 GetElementsIdFromParts( const ListOfIDSources& theParts )
2633 SMESH::long_array_var array = new SMESH::long_array;
2634 if ( theParts.length() > 0 && myPredicate )
2636 SMESH_Mesh_ptr mesh = theParts[0]->GetMesh();
2638 const SMDS_Mesh* meshDS = MeshPtr2SMDSMesh( mesh );
2639 Controls::Filter::TIdSequence totalSequence;
2640 for ( CORBA::ULong i = 0; i < theParts.length(); ++i )
2642 if ( SMESH::Filter_i* filter = SMESH::DownCast<SMESH::Filter_i*>( theParts[i] ))
2643 filter->SetMesh( mesh );
2644 SMDS_ElemIteratorPtr iter = SMESH_Mesh_i::GetElements( theParts[i], GetElementType() );
2645 if ( iter && meshDS )
2647 Controls::Filter::TIdSequence sequence;
2648 Controls::Filter::GetElementsId( meshDS, myPredicate->GetPredicate(), sequence, iter );
2649 totalSequence.insert( totalSequence.end(), sequence.begin(), sequence.end() );
2652 array->length( totalSequence.size() );
2653 for ( size_t i = 0; i < totalSequence.size(); ++i )
2654 array[ i ] = totalSequence[ i ];
2656 return array._retn();
2659 //=============================================================================
2661 * \brief Returns number of mesh elements per each \a EntityType
2663 //=============================================================================
2665 SMESH::long_array* ::Filter_i::GetMeshInfo()
2667 SMESH::long_array_var aRes = new SMESH::long_array();
2668 aRes->length(SMESH::Entity_Last);
2669 for (int i = 0; i < SMESH::Entity_Last; i++)
2672 if ( !CORBA::is_nil(myMesh) && myPredicate )
2674 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2675 SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2676 while ( it->more() )
2678 const SMDS_MeshElement* anElem = it->next();
2679 if ( myPredicate->IsSatisfy( anElem->GetID() ) )
2680 aRes[ anElem->GetEntityType() ]++;
2684 return aRes._retn();
2687 //=============================================================================
2689 * \brief Returns number of mesh elements of each \a ElementType
2691 //=============================================================================
2693 SMESH::long_array* ::Filter_i::GetNbElementsByType()
2695 SMESH::long_array_var aRes = new SMESH::long_array();
2696 aRes->length(SMESH::NB_ELEMENT_TYPES);
2697 for (int i = 0; i < SMESH::NB_ELEMENT_TYPES; i++)
2700 if ( !CORBA::is_nil(myMesh) && myPredicate ) {
2701 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2702 SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2703 CORBA::Long& nbElems = aRes[ GetElementType() ];
2704 while ( it->more() )
2706 const SMDS_MeshElement* anElem = it->next();
2707 if ( myPredicate->IsSatisfy( anElem->GetID() ) )
2712 return aRes._retn();
2716 //================================================================================
2718 * \brief Return GetElementType() within an array
2719 * Implement SMESH_IDSource interface
2721 //================================================================================
2723 SMESH::array_of_ElementType* Filter_i::GetTypes()
2725 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
2727 // check if any element passes through the filter
2728 if ( !CORBA::is_nil(myMesh) && myPredicate )
2730 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2731 SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
2732 bool satisfies = false;
2733 while ( !satisfies && it->more() )
2734 satisfies = myPredicate->IsSatisfy( it->next()->GetID() );
2737 types[0] = GetElementType();
2740 return types._retn();
2743 //=======================================================================
2744 //function : GetMesh
2745 //purpose : Returns mesh
2746 //=======================================================================
2748 SMESH::SMESH_Mesh_ptr Filter_i::GetMesh()
2750 return SMESH_Mesh::_duplicate( myMesh );
2753 //=======================================================================
2754 //function : GetVtkUgStream
2755 //purpose : Return data vtk unstructured grid (not implemented)
2756 //=======================================================================
2758 SALOMEDS::TMPFile* Filter_i::GetVtkUgStream()
2760 SALOMEDS::TMPFile_var SeqFile;
2761 return SeqFile._retn();
2763 //=======================================================================
2764 // name : getCriteria
2765 // Purpose : Retrieve criterions from predicate
2766 //=======================================================================
2767 static inline void getPrediacates( Predicate_i* thePred,
2768 std::vector<Predicate_i*> & thePredVec )
2770 const int aFType = thePred->GetFunctorType();
2776 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2777 getPrediacates( aPred, thePredVec );
2783 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2784 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2785 getPrediacates( aPred1, thePredVec );
2786 getPrediacates( aPred2, thePredVec );
2791 thePredVec.push_back( thePred );
2794 //=======================================================================
2795 // name : getCriteria
2796 // Purpose : Retrieve criterions from predicate
2797 //=======================================================================
2798 static inline bool getCriteria( Predicate_i* thePred,
2799 SMESH::Filter::Criteria_out theCriteria )
2801 const int aFType = thePred->GetFunctorType();
2807 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2808 getCriteria( aPred, theCriteria );
2809 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2816 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2817 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2818 if ( !getCriteria( aPred1, theCriteria ) )
2820 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2821 return getCriteria( aPred2, theCriteria );
2827 // resize theCriteria
2828 CORBA::ULong i = theCriteria->length();
2829 theCriteria->length( i + 1 );
2830 theCriteria[ i ] = createCriterion();
2832 // set members of the added Criterion
2834 theCriteria[ i ].Type = aFType;
2835 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
2839 case FT_FreeBorders:
2842 case FT_LinearOrQuadratic:
2846 case FT_EqualVolumes:
2847 case FT_BadOrientedVolume:
2848 case FT_BareBorderVolume:
2849 case FT_BareBorderFace:
2850 case FT_OverConstrainedVolume:
2851 case FT_OverConstrainedFace:
2855 case FT_BelongToMeshGroup:
2857 BelongToMeshGroup_i* aPred = dynamic_cast<BelongToMeshGroup_i*>( thePred );
2858 SMESH::SMESH_GroupBase_var grp = aPred->GetGroup();
2859 if ( !grp->_is_nil() )
2861 theCriteria[ i ].ThresholdStr = grp->GetName();
2862 theCriteria[ i ].ThresholdID = aPred->GetGroupID().c_str();
2866 case FT_BelongToGeom:
2868 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
2869 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2870 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2871 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2874 case FT_BelongToPlane:
2875 case FT_BelongToCylinder:
2876 case FT_BelongToGenSurface:
2878 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
2879 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2880 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2881 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2884 case FT_LyingOnGeom:
2886 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
2887 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2888 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2889 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2892 case FT_CoplanarFaces:
2894 CoplanarFaces_i* aPred = dynamic_cast<CoplanarFaces_i*>( thePred );
2895 theCriteria[ i ].ThresholdID = aPred->GetFaceAsString();
2896 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2899 case FT_ConnectedElements:
2901 ConnectedElements_i* aPred = dynamic_cast<ConnectedElements_i*>( thePred );
2902 SMESH::ConnectedElements::ThresholdType type;
2903 CORBA::String_var threshold = aPred->GetThreshold( type );
2905 case SMESH::ConnectedElements::POINT:
2906 theCriteria[ i ].ThresholdStr = threshold; break;
2907 case SMESH::ConnectedElements::VERTEX:
2908 theCriteria[ i ].ThresholdID = threshold; break;
2909 case SMESH::ConnectedElements::NODE:
2910 theCriteria[ i ].Threshold = atof( threshold.in() ); break;
2917 EqualNodes_i* aPred = dynamic_cast<EqualNodes_i*>( thePred );
2918 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2923 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
2924 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
2931 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
2932 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
2933 theCriteria[ i ].Compare = aFType;
2934 theCriteria[ i ].Threshold = aCompar->GetMargin();
2935 if ( aFType == FT_EqualTo )
2937 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
2938 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
2944 GroupColor_i* aPred = dynamic_cast<GroupColor_i*>( thePred );
2945 theCriteria[ i ].ThresholdStr = aPred->GetColorStr();
2948 case FT_ElemGeomType:
2950 ElemGeomType_i* aPred = dynamic_cast<ElemGeomType_i*>( thePred );
2951 theCriteria[ i ].Threshold = (double)aPred->GetGeometryType();
2956 ElemEntityType_i* aPred = dynamic_cast<ElemEntityType_i*>( thePred );
2957 theCriteria[ i ].Threshold = (double)aPred->GetEntityType();
2965 //=======================================================================
2966 // name : Filter_i::GetCriteria
2967 // Purpose : Retrieve criterions from predicate
2968 //=======================================================================
2969 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2971 theCriteria = new SMESH::Filter::Criteria;
2972 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2975 //=======================================================================
2976 // name : Filter_i::SetCriteria
2977 // Purpose : Create new predicate and set criterions in it
2978 //=======================================================================
2979 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2981 SetPredicate( SMESH::Predicate::_nil() );
2983 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2984 FilterManager_ptr aFilterMgr = aFilter->_this();
2986 // CREATE two lists ( PREDICATES and LOG OP )
2989 TPythonDump()<<"aCriteria = []";
2990 std::list<SMESH::Predicate_ptr> aPredicates;
2991 std::list<int> aBinaries;
2992 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2994 int aCriterion = theCriteria[ i ].Type;
2995 int aCompare = theCriteria[ i ].Compare;
2996 double aThreshold = theCriteria[ i ].Threshold;
2997 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2998 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2999 int aUnary = theCriteria[ i ].UnaryOp;
3000 int aBinary = theCriteria[ i ].BinaryOp;
3001 double aTolerance = theCriteria[ i ].Tolerance;
3002 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
3003 long aPrecision = theCriteria[ i ].Precision;
3007 pd << "aCriterion = SMESH.Filter.Criterion("
3008 << aCriterion << ", "
3010 << aThreshold << ", '"
3011 << aThresholdStr << "', '"
3012 << aThresholdID << "', "
3015 << aTolerance << ", "
3016 << aTypeOfElem << ", "
3017 << aPrecision << ")";
3021 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
3022 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
3024 switch ( aCriterion )
3028 case SMESH::FT_MultiConnection:
3029 aFunctor = aFilterMgr->CreateMultiConnection();
3031 case SMESH::FT_MultiConnection2D:
3032 aFunctor = aFilterMgr->CreateMultiConnection2D();
3034 case SMESH::FT_Length:
3035 aFunctor = aFilterMgr->CreateLength();
3037 case SMESH::FT_Length2D:
3038 aFunctor = aFilterMgr->CreateLength2D();
3040 case SMESH::FT_Length3D:
3041 aFunctor = aFilterMgr->CreateLength3D();
3043 case SMESH::FT_Deflection2D:
3044 aFunctor = aFilterMgr->CreateDeflection2D();
3046 case SMESH::FT_AspectRatio:
3047 aFunctor = aFilterMgr->CreateAspectRatio();
3049 case SMESH::FT_AspectRatio3D:
3050 aFunctor = aFilterMgr->CreateAspectRatio3D();
3052 case SMESH::FT_Warping:
3053 aFunctor = aFilterMgr->CreateWarping();
3055 case SMESH::FT_MinimumAngle:
3056 aFunctor = aFilterMgr->CreateMinimumAngle();
3058 case SMESH::FT_Taper:
3059 aFunctor = aFilterMgr->CreateTaper();
3061 case SMESH::FT_Skew:
3062 aFunctor = aFilterMgr->CreateSkew();
3064 case SMESH::FT_Area:
3065 aFunctor = aFilterMgr->CreateArea();
3067 case SMESH::FT_Volume3D:
3068 aFunctor = aFilterMgr->CreateVolume3D();
3070 case SMESH::FT_MaxElementLength2D:
3071 aFunctor = aFilterMgr->CreateMaxElementLength2D();
3073 case SMESH::FT_MaxElementLength3D:
3074 aFunctor = aFilterMgr->CreateMaxElementLength3D();
3076 case SMESH::FT_BallDiameter:
3077 aFunctor = aFilterMgr->CreateBallDiameter();
3079 case SMESH::FT_NodeConnectivityNumber:
3080 aFunctor = aFilterMgr->CreateNodeConnectivityNumber();
3085 case SMESH::FT_FreeBorders:
3086 aPredicate = aFilterMgr->CreateFreeBorders();
3088 case SMESH::FT_FreeEdges:
3089 aPredicate = aFilterMgr->CreateFreeEdges();
3091 case SMESH::FT_FreeFaces:
3092 aPredicate = aFilterMgr->CreateFreeFaces();
3094 case SMESH::FT_FreeNodes:
3095 aPredicate = aFilterMgr->CreateFreeNodes();
3097 case SMESH::FT_EqualNodes:
3099 SMESH::EqualNodes_ptr pred = aFilterMgr->CreateEqualNodes();
3100 pred->SetTolerance( aTolerance );
3104 case SMESH::FT_EqualEdges:
3105 aPredicate = aFilterMgr->CreateEqualEdges();
3107 case SMESH::FT_EqualFaces:
3108 aPredicate = aFilterMgr->CreateEqualFaces();
3110 case SMESH::FT_EqualVolumes:
3111 aPredicate = aFilterMgr->CreateEqualVolumes();
3113 case SMESH::FT_BelongToMeshGroup:
3115 SMESH::BelongToMeshGroup_ptr tmpPred = aFilterMgr->CreateBelongToMeshGroup();
3116 tmpPred->SetGroupID( aThresholdID );
3117 aPredicate = tmpPred;
3120 case SMESH::FT_BelongToGeom:
3122 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
3123 tmpPred->SetElementType( aTypeOfElem );
3124 tmpPred->SetShape( aThresholdID, aThresholdStr );
3125 tmpPred->SetTolerance( aTolerance );
3126 aPredicate = tmpPred;
3129 case SMESH::FT_BelongToPlane:
3130 case SMESH::FT_BelongToCylinder:
3131 case SMESH::FT_BelongToGenSurface:
3133 SMESH::BelongToSurface_ptr tmpPred;
3134 switch ( aCriterion ) {
3135 case SMESH::FT_BelongToPlane:
3136 tmpPred = aFilterMgr->CreateBelongToPlane(); break;
3137 case SMESH::FT_BelongToCylinder:
3138 tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
3140 tmpPred = aFilterMgr->CreateBelongToGenSurface();
3142 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
3143 tmpPred->SetTolerance( aTolerance );
3144 aPredicate = tmpPred;
3147 case SMESH::FT_LyingOnGeom:
3149 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
3150 tmpPred->SetElementType( aTypeOfElem );
3151 tmpPred->SetShape( aThresholdID, aThresholdStr );
3152 tmpPred->SetTolerance( aTolerance );
3153 aPredicate = tmpPred;
3156 case SMESH::FT_RangeOfIds:
3158 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
3159 tmpPred->SetRangeStr( aThresholdStr );
3160 tmpPred->SetElementType( aTypeOfElem );
3161 aPredicate = tmpPred;
3164 case SMESH::FT_BadOrientedVolume:
3166 aPredicate = aFilterMgr->CreateBadOrientedVolume();
3169 case SMESH::FT_BareBorderVolume:
3171 aPredicate = aFilterMgr->CreateBareBorderVolume();
3174 case SMESH::FT_BareBorderFace:
3176 aPredicate = aFilterMgr->CreateBareBorderFace();
3179 case SMESH::FT_OverConstrainedVolume:
3181 aPredicate = aFilterMgr->CreateOverConstrainedVolume();
3184 case SMESH::FT_OverConstrainedFace:
3186 aPredicate = aFilterMgr->CreateOverConstrainedFace();
3189 case SMESH::FT_LinearOrQuadratic:
3191 SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
3192 tmpPred->SetElementType( aTypeOfElem );
3193 aPredicate = tmpPred;
3196 case SMESH::FT_GroupColor:
3198 SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor();
3199 tmpPred->SetElementType( aTypeOfElem );
3200 tmpPred->SetColorStr( aThresholdStr );
3201 aPredicate = tmpPred;
3204 case SMESH::FT_ElemGeomType:
3206 SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType();
3207 tmpPred->SetElementType( aTypeOfElem );
3208 tmpPred->SetGeometryType( (GeometryType)(int)(aThreshold + 0.5) );
3209 aPredicate = tmpPred;
3212 case SMESH::FT_EntityType:
3214 SMESH::ElemEntityType_ptr tmpPred = aFilterMgr->CreateElemEntityType();
3215 tmpPred->SetElementType( aTypeOfElem );
3216 tmpPred->SetEntityType( EntityType( (int (aThreshold + 0.5))));
3217 aPredicate = tmpPred;
3220 case SMESH::FT_CoplanarFaces:
3222 SMESH::CoplanarFaces_ptr tmpPred = aFilterMgr->CreateCoplanarFaces();
3223 tmpPred->SetFace( atol (aThresholdID ));
3224 tmpPred->SetTolerance( aTolerance );
3225 aPredicate = tmpPred;
3228 case SMESH::FT_ConnectedElements:
3230 SMESH::ConnectedElements_ptr tmpPred = aFilterMgr->CreateConnectedElements();
3231 if ( strlen( aThresholdID ) > 0 ) // shape ID
3232 tmpPred->SetThreshold( aThresholdID, SMESH::ConnectedElements::VERTEX );
3233 else if ( strlen( aThresholdStr ) > 0 ) // point coords
3234 tmpPred->SetThreshold( aThresholdStr, SMESH::ConnectedElements::POINT );
3235 else if ( aThreshold >= 1 )
3236 tmpPred->SetNode( (CORBA::Long) aThreshold ); // node ID
3237 tmpPred->SetElementType( aTypeOfElem );
3238 aPredicate = tmpPred;
3247 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
3249 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
3251 if ( aCompare == SMESH::FT_LessThan )
3252 aComparator = aFilterMgr->CreateLessThan();
3253 else if ( aCompare == SMESH::FT_MoreThan )
3254 aComparator = aFilterMgr->CreateMoreThan();
3255 else if ( aCompare == SMESH::FT_EqualTo )
3256 aComparator = aFilterMgr->CreateEqualTo();
3260 aComparator->SetNumFunctor( aFunctor );
3261 aComparator->SetMargin( aThreshold );
3263 if ( aCompare == FT_EqualTo )
3265 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
3266 anEqualTo->SetTolerance( aTolerance );
3269 aPredicate = aComparator;
3271 aFunctor->SetPrecision( aPrecision );
3275 if ( aUnary == FT_LogicalNOT )
3277 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
3278 aNotPred->SetPredicate( aPredicate );
3279 aPredicate = aNotPred;
3283 aPredicates.push_back( aPredicate );
3284 aBinaries.push_back( aBinary );
3285 pd <<"aCriteria.append(aCriterion)";
3288 TPythonDump pd; pd<<this<<".SetCriteria(aCriteria)";
3290 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
3292 // combine all "AND" operations
3294 std::list<SMESH::Predicate_ptr> aResList;
3296 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
3297 std::list<int>::iterator aBinaryIter;
3299 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
3300 int aPrevBinary = SMESH::FT_Undefined;
3301 if ( !aBinaries.empty() )
3302 aBinaries.back() = SMESH::FT_Undefined;
3304 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
3305 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
3306 ++aPredIter, ++aBinaryIter )
3308 int aCurrBinary = *aBinaryIter;
3310 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
3312 if ( aPrevBinary == SMESH::FT_LogicalAND )
3315 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
3316 aBinaryPred->SetPredicate1( aPrevPredicate );
3317 aBinaryPred->SetPredicate2( *aPredIter );
3318 aCurrPred = aBinaryPred;
3321 aCurrPred = *aPredIter;
3323 if ( aCurrBinary != SMESH::FT_LogicalAND )
3324 aResList.push_back( aCurrPred );
3326 aPrevPredicate = aCurrPred;
3327 aPrevBinary = aCurrBinary;
3330 // combine all "OR" operations
3332 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
3334 if ( aResList.size() == 1 )
3335 aResPredicate = *aResList.begin();
3336 else if ( aResList.size() > 1 )
3338 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
3339 aResPredicate = *anIter;
3341 for ( ; anIter != aResList.end(); ++anIter )
3343 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
3344 aBinaryPred->SetPredicate1( aResPredicate );
3345 aBinaryPred->SetPredicate2( *anIter );
3346 aResPredicate = aBinaryPred;
3350 SetPredicate( aResPredicate );
3351 if ( !aResPredicate->_is_nil() )
3352 aResPredicate->UnRegister();
3354 return !aResPredicate->_is_nil();
3357 //=======================================================================
3358 // name : Filter_i::GetPredicate_i
3359 // Purpose : Get implementation of predicate
3360 //=======================================================================
3361 Predicate_i* Filter_i::GetPredicate_i()
3366 //=======================================================================
3367 // name : Filter_i::GetPredicate
3368 // Purpose : Get predicate
3369 //=======================================================================
3370 Predicate_ptr Filter_i::GetPredicate()
3372 if ( myPredicate == 0 )
3373 return SMESH::Predicate::_nil();
3376 SMESH::Predicate_var anObj = myPredicate->_this();
3377 // if ( SMESH::Functor_i* fun = SMESH::DownCast<SMESH::Functor_i*>( anObj ))
3378 // TPythonDump() << fun << " = " << this << ".GetPredicate()";
3379 return anObj._retn();
3383 //================================================================================
3385 * \brief Find groups it depends on
3387 //================================================================================
3389 void Filter_i::FindBaseObjects()
3391 // release current groups
3392 for ( size_t i = 0; i < myBaseGroups.size(); ++i )
3393 if ( myBaseGroups[i] )
3395 myBaseGroups[i]->RemoveModifWaiter( this );
3396 myBaseGroups[i]->UnRegister();
3399 // remember new groups
3400 myBaseGroups.clear();
3403 std::vector<Predicate_i*> predicates;
3404 getPrediacates( myPredicate, predicates );
3405 for ( size_t i = 0; i < predicates.size(); ++i )
3406 if ( BelongToMeshGroup_i* bmg = dynamic_cast< BelongToMeshGroup_i* >( predicates[i] ))
3408 SMESH::SMESH_GroupBase_var g = bmg->GetGroup();
3409 SMESH_GroupBase_i* g_i = SMESH::DownCast< SMESH_GroupBase_i*>( g );
3412 g_i->AddModifWaiter( this );
3414 myBaseGroups.push_back( g_i );
3420 //================================================================================
3422 * \brief When notified on removal of myBaseGroups[i], remove a reference to a
3423 * group from a predicate
3425 //================================================================================
3427 void Filter_i::OnBaseObjModified(NotifyerAndWaiter* group, bool removed)
3430 return; // a GroupOnFilter holding this filter is notified automatically
3434 std::vector<Predicate_i*> predicates;
3435 getPrediacates( myPredicate, predicates );
3436 for ( size_t i = 0; i < predicates.size(); ++i )
3437 if ( BelongToMeshGroup_i* bmg = dynamic_cast< BelongToMeshGroup_i* >( predicates[i] ))
3439 SMESH::SMESH_GroupBase_var g = bmg->GetGroup();
3440 SMESH_GroupBase_i* g_i = SMESH::DownCast< SMESH_GroupBase_i*>( g );
3443 bmg->SetGroup( SMESH::SMESH_GroupBase::_nil() );
3444 bmg->SetGroupID( "" );
3449 FindBaseObjects(); // release and update myBaseGroups;
3456 #define ATTR_TYPE "type"
3457 #define ATTR_COMPARE "compare"
3458 #define ATTR_THRESHOLD "threshold"
3459 #define ATTR_UNARY "unary"
3460 #define ATTR_BINARY "binary"
3461 #define ATTR_THRESHOLD_STR "threshold_str"
3462 #define ATTR_TOLERANCE "tolerance"
3463 #define ATTR_ELEMENT_TYPE "ElementType"
3465 //=======================================================================
3467 // Purpose : Convert bool to LDOMString
3468 //=======================================================================
3469 static inline LDOMString toString( CORBA::Boolean val )
3471 return val ? "logical not" : "";
3474 //=======================================================================
3476 // Purpose : Convert LDOMString to bool
3477 //=======================================================================
3478 static inline bool toBool( const LDOMString& theStr )
3480 return theStr.equals( "logical not" );
3483 //=======================================================================
3485 // Purpose : Convert double to LDOMString
3486 //=======================================================================
3487 static inline LDOMString toString( CORBA::Double val )
3490 sprintf( a, "%e", val );
3491 return LDOMString( a );
3494 //=======================================================================
3496 // Purpose : Convert LDOMString to double
3497 //=======================================================================
3498 static inline double toDouble( const LDOMString& theStr )
3500 return atof( theStr.GetString() );
3503 //=======================================================================
3505 // Purpose : Convert functor type to LDOMString
3506 //=======================================================================
3507 static inline LDOMString toString( CORBA::Long theType )
3511 case FT_AspectRatio : return "Aspect ratio";
3512 case FT_Warping : return "Warping";
3513 case FT_MinimumAngle : return "Minimum angle";
3514 case FT_Taper : return "Taper";
3515 case FT_Skew : return "Skew";
3516 case FT_Area : return "Area";
3517 case FT_Volume3D : return "Volume3D";
3518 case FT_MaxElementLength2D : return "Max element length 2D";
3519 case FT_MaxElementLength3D : return "Max element length 3D";
3520 case FT_BelongToMeshGroup : return "Belong to Mesh Group";
3521 case FT_BelongToGeom : return "Belong to Geom";
3522 case FT_BelongToPlane : return "Belong to Plane";
3523 case FT_BelongToCylinder : return "Belong to Cylinder";
3524 case FT_BelongToGenSurface : return "Belong to Generic Surface";
3525 case FT_LyingOnGeom : return "Lying on Geom";
3526 case FT_BadOrientedVolume : return "Bad Oriented Volume";
3527 case FT_BareBorderVolume : return "Volumes with bare border";
3528 case FT_BareBorderFace : return "Faces with bare border";
3529 case FT_OverConstrainedVolume : return "Over-constrained Volumes";
3530 case FT_OverConstrainedFace : return "Over-constrained Faces";
3531 case FT_RangeOfIds : return "Range of IDs";
3532 case FT_FreeBorders : return "Free borders";
3533 case FT_FreeEdges : return "Free edges";
3534 case FT_FreeFaces : return "Free faces";
3535 case FT_FreeNodes : return "Free nodes";
3536 case FT_EqualNodes : return "Equal nodes";
3537 case FT_EqualEdges : return "Equal edges";
3538 case FT_EqualFaces : return "Equal faces";
3539 case FT_EqualVolumes : return "Equal volumes";
3540 case FT_MultiConnection : return "Borders at multi-connections";
3541 case FT_MultiConnection2D : return "Borders at multi-connections 2D";
3542 case FT_Length : return "Length";
3543 case FT_Length2D : return "Length 2D";
3544 case FT_Length3D : return "Length 3D";
3545 case FT_Deflection2D : return "Deflection 2D";
3546 case FT_LessThan : return "Less than";
3547 case FT_MoreThan : return "More than";
3548 case FT_EqualTo : return "Equal to";
3549 case FT_LogicalNOT : return "Not";
3550 case FT_LogicalAND : return "And";
3551 case FT_LogicalOR : return "Or";
3552 case FT_GroupColor : return "Color of Group";
3553 case FT_LinearOrQuadratic : return "Linear or Quadratic";
3554 case FT_ElemGeomType : return "Element geometry type";
3555 case FT_EntityType : return "Entity type";
3556 case FT_Undefined : return "";
3557 default : return "";
3561 //=======================================================================
3562 // name : toFunctorType
3563 // Purpose : Convert LDOMString to functor type
3564 //=======================================================================
3565 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
3567 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
3568 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
3569 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
3570 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
3571 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
3572 else if ( theStr.equals( "Area" ) ) return FT_Area;
3573 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
3574 else if ( theStr.equals( "Max element length 2D" ) ) return FT_MaxElementLength2D;
3575 else if ( theStr.equals( "Max element length 3D" ) ) return FT_MaxElementLength3D;
3576 else if ( theStr.equals( "Belong to Mesh Group" ) ) return FT_BelongToMeshGroup;
3577 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
3578 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
3579 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
3580 else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface;
3581 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
3582 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
3583 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
3584 else if ( theStr.equals( "Free faces" ) ) return FT_FreeFaces;
3585 else if ( theStr.equals( "Free nodes" ) ) return FT_FreeNodes;
3586 else if ( theStr.equals( "Equal nodes" ) ) return FT_EqualNodes;
3587 else if ( theStr.equals( "Equal edges" ) ) return FT_EqualEdges;
3588 else if ( theStr.equals( "Equal faces" ) ) return FT_EqualFaces;
3589 else if ( theStr.equals( "Equal volumes" ) ) return FT_EqualVolumes;
3590 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
3591 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
3592 else if ( theStr.equals( "Length" ) ) return FT_Length;
3593 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
3594 // else if ( theStr.equals( "Length3D" ) ) return FT_Length3D;
3595 else if ( theStr.equals( "Deflection" ) ) return FT_Deflection2D;
3596 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
3597 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
3598 else if ( theStr.equals( "Volumes with bare border" ) ) return FT_BareBorderVolume;
3599 else if ( theStr.equals( "Faces with bare border" ) ) return FT_BareBorderFace;
3600 else if ( theStr.equals( "Over-constrained Volumes" ) ) return FT_OverConstrainedVolume;
3601 else if ( theStr.equals( "Over-constrained Faces" ) ) return FT_OverConstrainedFace;
3602 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
3603 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
3604 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
3605 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
3606 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
3607 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
3608 else if ( theStr.equals( "Color of Group" ) ) return FT_GroupColor;
3609 else if ( theStr.equals( "Linear or Quadratic" ) ) return FT_LinearOrQuadratic;
3610 else if ( theStr.equals( "Element geometry type" ) ) return FT_ElemGeomType;
3611 else if ( theStr.equals( "Entity type" ) ) return FT_EntityType;
3612 else if ( theStr.equals( "" ) ) return FT_Undefined;
3613 else return FT_Undefined;
3616 //=======================================================================
3617 // name : toFunctorType
3618 // Purpose : Convert LDOMString to value of ElementType enumeration
3619 //=======================================================================
3620 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
3622 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
3623 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
3624 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
3625 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
3626 else return SMESH::ALL;
3629 //=======================================================================
3631 // Purpose : Convert ElementType to string
3632 //=======================================================================
3633 static inline LDOMString toString( const SMESH::ElementType theType )
3637 case SMESH::NODE : return "NODE";
3638 case SMESH::EDGE : return "EDGE";
3639 case SMESH::FACE : return "FACE";
3640 case SMESH::VOLUME : return "VOLUME";
3641 case SMESH::ALL : return "ALL";
3642 default : return "";
3646 //=======================================================================
3647 // name : findFilter
3648 // Purpose : Find filter in document
3649 //=======================================================================
3650 static LDOM_Element findFilter( const char* theFilterName,
3651 const LDOM_Document& theDoc,
3652 LDOM_Node* theParent = 0 )
3654 LDOM_Element aRootElement = theDoc.getDocumentElement();
3655 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
3656 return LDOM_Element();
3658 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
3659 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
3661 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
3662 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3664 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
3665 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
3666 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
3668 if ( theParent != 0 )
3669 *theParent = aTypeNode;
3670 return (LDOM_Element&)aFilter;
3674 return LDOM_Element();
3677 //=======================================================================
3678 // name : getSectionName
3679 // Purpose : Get name of section of filters
3680 //=======================================================================
3681 static const char* getSectionName( const ElementType theType )
3685 case SMESH::NODE : return "Filters for nodes";
3686 case SMESH::EDGE : return "Filters for edges";
3687 case SMESH::FACE : return "Filters for faces";
3688 case SMESH::VOLUME : return "Filters for volumes";
3689 case SMESH::ALL : return "Filters for elements";
3690 default : return "";
3694 //=======================================================================
3695 // name : getSection
3696 // Purpose : Create section for filters corresponding to the entity type
3697 //=======================================================================
3698 static LDOM_Node getSection( const ElementType theType,
3699 LDOM_Document& theDoc,
3700 const bool toCreate = false )
3702 LDOM_Element aRootElement = theDoc.getDocumentElement();
3703 if ( aRootElement.isNull() )
3707 bool anExist = false;
3708 const char* aSectionName = getSectionName( theType );
3709 if ( strcmp( aSectionName, "" ) == 0 )
3712 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
3714 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
3716 aNode = aSections.item( i );
3717 LDOM_Element& anItem = ( LDOM_Element& )aNode;
3718 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
3725 // Create new section if necessary
3730 LDOM_Element aNewItem = theDoc.createElement( "section" );
3731 aNewItem.setAttribute( "name", aSectionName );
3732 aRootElement.appendChild( aNewItem );
3742 //=======================================================================
3743 // name : createFilterItem
3744 // Purpose : Create filter item or LDOM document
3745 //=======================================================================
3746 static LDOM_Element createFilterItem( const char* theName,
3747 SMESH::Filter_ptr theFilter,
3748 LDOM_Document& theDoc )
3750 // create new filter in document
3751 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
3752 aFilterItem.setAttribute( "name", theName );
3754 // save filter criterions
3755 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3757 if ( !theFilter->GetCriteria( aCriteria ) )
3758 return LDOM_Element();
3760 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
3762 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
3764 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
3765 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
3766 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
3767 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
3768 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
3770 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
3771 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
3772 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
3773 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
3775 aFilterItem.appendChild( aCriterionItem );
3781 //=======================================================================
3782 // name : FilterLibrary_i::FilterLibrary_i
3783 // Purpose : Constructor
3784 //=======================================================================
3785 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
3787 myFileName = CORBA::string_dup( theFileName );
3788 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
3789 myFilterMgr = aFilterMgr->_this();
3793 // Try to use existing library file
3794 bool anExists = false;
3795 if ( !aParser.parse( myFileName ) )
3797 myDoc = aParser.getDocument();
3800 // Create a new XML document if it doesn't exist
3802 myDoc = LDOM_Document::createDocument( LDOMString() );
3804 LDOM_Element aRootElement = myDoc.getDocumentElement();
3805 if ( aRootElement.isNull() )
3807 // If the existing document is empty --> try to create a new one
3809 myDoc = LDOM_Document::createDocument( LDOMString() );
3813 //=======================================================================
3814 // name : FilterLibrary_i::FilterLibrary_i
3815 // Purpose : Constructor
3816 //=======================================================================
3817 FilterLibrary_i::FilterLibrary_i()
3820 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
3821 myFilterMgr = aFilter->_this();
3823 myDoc = LDOM_Document::createDocument( LDOMString() );
3826 FilterLibrary_i::~FilterLibrary_i()
3828 CORBA::string_free( myFileName );
3829 //TPythonDump()<<this<<".UnRegister()";
3832 //=======================================================================
3833 // name : FilterLibrary_i::Copy
3834 // Purpose : Create filter and initialize it with values from library
3835 //=======================================================================
3836 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
3838 Filter_ptr aRes = Filter::_nil();
3839 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
3841 if ( aFilter.isNull() )
3844 std::list<SMESH::Filter::Criterion> aCriteria;
3846 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
3847 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
3849 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
3851 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
3852 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
3853 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
3854 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
3855 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
3857 SMESH::Filter::Criterion aCriterion = createCriterion();
3859 aCriterion.Type = toFunctorType( aTypeStr );
3860 aCriterion.Compare = toFunctorType( aCompareStr );
3861 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
3862 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
3864 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
3866 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
3868 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3869 ? val : atof( str.GetString() );
3871 str = aCrit->getAttribute( ATTR_TOLERANCE );
3872 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3873 ? val : atof( str.GetString() );
3875 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
3876 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
3879 sprintf( a, "%d", val );
3880 aCriterion.ThresholdStr = CORBA::string_dup( a );
3883 aCriterion.ThresholdStr = str.GetString();
3885 aCriteria.push_back( aCriterion );
3888 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
3889 aCriteriaVar->length( aCriteria.size() );
3892 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
3894 for( ; anIter != aCriteria.end(); ++anIter )
3895 aCriteriaVar[ i++ ] = *anIter;
3897 aRes = myFilterMgr->CreateFilter();
3898 aRes->SetCriteria( aCriteriaVar.inout() );
3900 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
3905 //=======================================================================
3906 // name : FilterLibrary_i::SetFileName
3907 // Purpose : Set file name for library
3908 //=======================================================================
3909 void FilterLibrary_i::SetFileName( const char* theFileName )
3911 CORBA::string_free( myFileName );
3912 myFileName = CORBA::string_dup( theFileName );
3913 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
3916 //=======================================================================
3917 // name : FilterLibrary_i::GetFileName
3918 // Purpose : Get file name of library
3919 //=======================================================================
3920 char* FilterLibrary_i::GetFileName()
3922 return CORBA::string_dup( myFileName );
3925 //=======================================================================
3926 // name : FilterLibrary_i::Add
3927 // Purpose : Add new filter to library
3928 //=======================================================================
3929 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
3931 // if filter already in library or entry filter is null do nothing
3932 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3933 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
3936 // get section corresponding to the filter type
3937 ElementType anEntType = theFilter->GetElementType();
3939 LDOM_Node aSection = getSection( anEntType, myDoc, true );
3940 if ( aSection.isNull() )
3943 // create filter item
3944 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
3945 if ( aFilterItem.isNull() )
3949 aSection.appendChild( aFilterItem );
3950 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3951 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
3956 //=======================================================================
3957 // name : FilterLibrary_i::Add
3958 // Purpose : Add new filter to library
3959 //=======================================================================
3960 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
3962 // if filter already in library or entry filter is null do nothing
3963 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3964 if ( !aFilterNode.isNull() )
3967 LDOM_Node aSection = getSection( theType, myDoc, true );
3968 if ( aSection.isNull() )
3971 // create filter item
3972 Filter_var aFilter = myFilterMgr->CreateFilter();
3974 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
3975 if ( aFilterItem.isNull() )
3979 aSection.appendChild( aFilterItem );
3980 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
3985 //=======================================================================
3986 // name : FilterLibrary_i::Delete
3987 // Purpose : Delete filter from library
3988 //=======================================================================
3989 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
3991 LDOM_Node aParentNode;
3992 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
3993 if ( aFilterNode.isNull() || aParentNode.isNull() )
3996 aParentNode.removeChild( aFilterNode );
3997 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
4001 //=======================================================================
4002 // name : FilterLibrary_i::Replace
4003 // Purpose : Replace existing filter with entry filter.
4004 // IMPORTANT : If filter does not exist it is not created
4005 //=======================================================================
4006 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
4007 const char* theNewName,
4008 Filter_ptr theFilter )
4010 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
4011 if ( aFilterItem.isNull() || theFilter->_is_nil() )
4014 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
4015 if ( aNewItem.isNull() )
4019 aFilterItem.ReplaceElement( aNewItem );
4020 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
4021 TPythonDump()<<this<<".Replace('"<<theFilterName<<"','"<<theNewName<<"',"<<aFilter<<")";
4026 //=======================================================================
4027 // name : FilterLibrary_i::Save
4028 // Purpose : Save library on disk
4029 //=======================================================================
4030 CORBA::Boolean FilterLibrary_i::Save()
4032 if ( myFileName == 0 || strlen( myFileName ) == 0 )
4036 fb.open( myFileName, std::ios::out );
4038 Standard_OStream os( &fb );
4040 LDOM_XmlWriter aWriter;
4041 aWriter.SetIndentation( 2 );
4042 aWriter.Write( os, myDoc );
4045 TPythonDump()<<this<<".Save()";
4049 //=======================================================================
4050 // name : FilterLibrary_i::SaveAs
4051 // Purpose : Save library on disk
4052 //=======================================================================
4053 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
4055 myFileName = strdup ( aFileName );
4056 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
4060 //=======================================================================
4061 // name : FilterLibrary_i::IsPresent
4062 // Purpose : Verify whether filter is in library
4063 //=======================================================================
4064 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
4066 return !findFilter( theFilterName, myDoc ).isNull();
4069 //=======================================================================
4070 // name : FilterLibrary_i::NbFilters
4071 // Purpose : Return amount of filters in library
4072 //=======================================================================
4073 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
4075 string_array_var aNames = GetNames( theType );
4076 return aNames->length();
4079 //=======================================================================
4080 // name : FilterLibrary_i::GetNames
4081 // Purpose : Get names of filters from library
4082 //=======================================================================
4083 string_array* FilterLibrary_i::GetNames( ElementType theType )
4085 string_array_var anArray = new string_array;
4086 TColStd_SequenceOfHAsciiString aSeq;
4088 LDOM_Node aSection = getSection( theType, myDoc, false );
4090 if ( !aSection.isNull() )
4092 for ( LDOM_Node aFilter = aSection.getFirstChild();
4093 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
4095 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
4096 aSeq.Append( new TCollection_HAsciiString(
4097 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
4101 anArray->length( aSeq.Length() );
4102 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
4103 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
4105 return anArray._retn();
4108 //=======================================================================
4109 // name : FilterLibrary_i::GetAllNames
4110 // Purpose : Get names of filters from library
4111 //=======================================================================
4112 string_array* FilterLibrary_i::GetAllNames()
4114 string_array_var aResArray = new string_array;
4115 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
4117 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
4119 int aPrevLength = aResArray->length();
4120 aResArray->length( aPrevLength + aNames->length() );
4121 for ( int i = 0, n = aNames->length(); i < n; i++ )
4122 aResArray[ aPrevLength + i ] = aNames[ i ];
4125 return aResArray._retn();
4128 //================================================================================
4130 * \brief Return an array of strings corresponding to items of enum FunctorType
4132 //================================================================================
4134 static const char** getFunctNames()
4136 static const char* functName[] = {
4137 // IT's necessary to update this array according to enum FunctorType (SMESH_Filter.idl)
4138 // The order is IMPORTANT !!!
4147 "FT_MaxElementLength2D",
4148 "FT_MaxElementLength3D",
4157 "FT_MultiConnection",
4158 "FT_MultiConnection2D",
4163 "FT_NodeConnectivityNumber",
4164 "FT_BelongToMeshGroup",
4167 "FT_BelongToCylinder",
4168 "FT_BelongToGenSurface",
4171 "FT_BadOrientedVolume",
4172 "FT_BareBorderVolume",
4173 "FT_BareBorderFace",
4174 "FT_OverConstrainedVolume",
4175 "FT_OverConstrainedFace",
4176 "FT_LinearOrQuadratic",
4182 "FT_ConnectedElements",
4192 // check if functName is complete, compilation failure means that enum FunctorType changed
4193 const int nbFunctors = sizeof(functName) / sizeof(const char*);
4194 int _assert[( nbFunctors == SMESH::FT_Undefined + 1 ) ? 2 : -1 ]; _assert[0]=_assert[1]=0;
4200 //================================================================================
4202 * \brief Return a string corresponding to an item of enum FunctorType
4204 //================================================================================
4206 const char* SMESH::FunctorTypeToString(SMESH::FunctorType ft)
4208 if ( ft < 0 || ft > SMESH::FT_Undefined )
4209 return "FT_Undefined";
4210 return getFunctNames()[ ft ];
4213 //================================================================================
4215 * \brief Converts a string to FunctorType. This is reverse of FunctorTypeToString()
4217 //================================================================================
4219 SMESH::FunctorType SMESH::StringToFunctorType(const char* str)
4221 std::string name( str + 3 ); // skip "FT_"
4222 const char** functNames = getFunctNames();
4224 for ( ; ft < SMESH::FT_Undefined; ++ft )
4225 if ( name == ( functNames[ft] + 3 ))
4228 //ASSERT( strcmp( str, FunctorTypeToString( SMESH::FunctorType( ft ))) == 0 );
4230 return SMESH::FunctorType( ft );
4233 //================================================================================
4235 * \brief calls OnBaseObjModified(), if who != this, and myWaiters[i]->Modified(who)
4237 //================================================================================
4239 void NotifyerAndWaiter::Modified( bool removed, NotifyerAndWaiter* who )
4241 if ( who != 0 && who != this )
4242 OnBaseObjModified( who, removed );
4246 std::list<NotifyerAndWaiter*> waiters = myWaiters; // myWaiters can be changed by Modified()
4247 std::list<NotifyerAndWaiter*>::iterator i = waiters.begin();
4248 for ( ; i != waiters.end(); ++i )
4249 (*i)->Modified( removed, who );
4252 //================================================================================
4254 * \brief Stores an object to be notified on change of predicate
4256 //================================================================================
4258 void NotifyerAndWaiter::AddModifWaiter( NotifyerAndWaiter* waiter )
4261 myWaiters.push_back( waiter );
4264 //================================================================================
4266 * \brief Removes an object to be notified on change of predicate
4268 //================================================================================
4270 void NotifyerAndWaiter::RemoveModifWaiter( NotifyerAndWaiter* waiter )
4272 myWaiters.remove( waiter );
4275 //================================================================================
4277 * \brief Checks if a waiter is among myWaiters, maybe nested
4279 //================================================================================
4281 bool NotifyerAndWaiter::ContainModifWaiter( NotifyerAndWaiter* waiter )
4283 bool is = ( waiter == this );
4285 std::list<NotifyerAndWaiter*>::iterator w = myWaiters.begin();
4286 for ( ; !is && w != myWaiters.end(); ++w )
4287 is = (*w)->ContainModifWaiter( waiter );