1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 // File : SMESH_Filter_i.cxx
25 // Author : Alexey Petrov, OCC
28 #include "SMESH_Filter_i.hxx"
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_PythonDump.hxx"
33 #include "SMDS_Mesh.hxx"
34 #include "SMDS_MeshNode.hxx"
35 #include "SMDS_MeshElement.hxx"
36 #include "SMDS_ElemIterator.hxx"
37 #include "SMDS_VolumeTool.hxx"
39 #include "SMESHDS_Mesh.hxx"
41 #include <BRep_Tool.hxx>
42 #include <Geom_CylindricalSurface.hxx>
43 #include <Geom_Plane.hxx>
44 #include <LDOMParser.hxx>
45 #include <LDOMString.hxx>
46 #include <LDOM_Document.hxx>
47 #include <LDOM_Element.hxx>
48 #include <LDOM_Node.hxx>
49 #include <LDOM_XmlWriter.hxx>
50 #include <Precision.hxx>
51 #include <TColStd_ListIteratorOfListOfInteger.hxx>
52 #include <TColStd_ListIteratorOfListOfReal.hxx>
53 #include <TColStd_ListOfInteger.hxx>
54 #include <TColStd_ListOfReal.hxx>
55 #include <TColStd_SequenceOfHAsciiString.hxx>
56 #include <TCollection_HAsciiString.hxx>
58 #include <TopExp_Explorer.hxx>
60 #include <TopoDS_Face.hxx>
61 #include <TopoDS_Shape.hxx>
62 #include <TopTools_IndexedMapOfShape.hxx>
64 using namespace SMESH;
65 using namespace SMESH::Controls;
71 GetPredicate( Predicate_ptr thePredicate )
73 return DownCast<Predicate_i*>(thePredicate);
80 Description : Predicate for verifying whether entity belongs to
81 specified geometrical support
84 Controls::BelongToGeom::BelongToGeom()
88 myTolerance(Precision::Confusion())
91 void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
93 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
97 void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
103 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
104 const TopoDS_Shape& theShape)
106 if (theMap.Contains(theShape)) return true;
108 if (theShape.ShapeType() == TopAbs_COMPOUND ||
109 theShape.ShapeType() == TopAbs_COMPSOLID)
111 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
112 for (; anIt.More(); anIt.Next())
114 if (!IsSubShape(theMap, anIt.Value())) {
124 void Controls::BelongToGeom::init()
126 if (!myMeshDS || myShape.IsNull()) return;
128 // is subshape of main shape?
129 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
130 if (aMainShape.IsNull()) {
131 myIsSubshape = false;
134 TopTools_IndexedMapOfShape aMap;
135 TopExp::MapShapes(aMainShape, aMap);
136 myIsSubshape = IsSubShape(aMap, myShape);
141 myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
142 myElementsOnShapePtr->SetTolerance(myTolerance);
143 myElementsOnShapePtr->SetAllNodes(true); // belong, while false means "lays on"
144 myElementsOnShapePtr->SetMesh(myMeshDS);
145 myElementsOnShapePtr->SetShape(myShape, myType);
149 static bool IsContains( const SMESHDS_Mesh* theMeshDS,
150 const TopoDS_Shape& theShape,
151 const SMDS_MeshElement* theElem,
152 TopAbs_ShapeEnum theFindShapeEnum,
153 TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE )
155 TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
157 while( anExp.More() )
159 const TopoDS_Shape& aShape = anExp.Current();
160 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
161 if( aSubMesh->Contains( theElem ) )
169 bool Controls::BelongToGeom::IsSatisfy (long theId)
171 if (myMeshDS == 0 || myShape.IsNull())
176 return myElementsOnShapePtr->IsSatisfy(theId);
180 if (myType == SMDSAbs_Node)
182 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
184 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
185 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
186 switch( aTypeOfPosition )
188 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
189 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
190 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
191 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
197 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
199 if( myType == SMDSAbs_All )
201 return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
202 IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
203 IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
204 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
206 else if( myType == anElem->GetType() )
210 case SMDSAbs_Edge : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
211 case SMDSAbs_Face : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
212 case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
213 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
222 void Controls::BelongToGeom::SetType (SMDSAbs_ElementType theType)
228 SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
233 TopoDS_Shape Controls::BelongToGeom::GetShape()
238 const SMESHDS_Mesh* Controls::BelongToGeom::GetMeshDS() const
243 void Controls::BelongToGeom::SetTolerance (double theTolerance)
245 myTolerance = theTolerance;
250 double Controls::BelongToGeom::GetTolerance()
257 Description : Predicate for verifying whether entiy lying or partially lying on
258 specified geometrical support
261 Controls::LyingOnGeom::LyingOnGeom()
265 myTolerance(Precision::Confusion())
268 void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
270 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
274 void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
280 void Controls::LyingOnGeom::init()
282 if (!myMeshDS || myShape.IsNull()) return;
284 // is subshape of main shape?
285 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
286 if (aMainShape.IsNull()) {
287 myIsSubshape = false;
290 TopTools_IndexedMapOfShape aMap;
291 TopExp::MapShapes(aMainShape, aMap);
292 myIsSubshape = IsSubShape(aMap, myShape);
297 myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
298 myElementsOnShapePtr->SetTolerance(myTolerance);
299 myElementsOnShapePtr->SetAllNodes(false); // lays on, while true means "belong"
300 myElementsOnShapePtr->SetMesh(myMeshDS);
301 myElementsOnShapePtr->SetShape(myShape, myType);
305 bool Controls::LyingOnGeom::IsSatisfy( long theId )
307 if ( myMeshDS == 0 || myShape.IsNull() )
312 return myElementsOnShapePtr->IsSatisfy(theId);
316 if( myType == SMDSAbs_Node )
318 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
320 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
321 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
322 switch( aTypeOfPosition )
324 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
325 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
326 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
327 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
333 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
335 if( myType == SMDSAbs_All )
337 return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
338 Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
339 Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
340 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
342 else if( myType == anElem->GetType() )
346 case SMDSAbs_Edge : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
347 case SMDSAbs_Face : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
348 case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
349 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
358 void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
364 SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
369 TopoDS_Shape Controls::LyingOnGeom::GetShape()
374 const SMESHDS_Mesh* Controls::LyingOnGeom::GetMeshDS() const
379 void Controls::LyingOnGeom::SetTolerance (double theTolerance)
381 myTolerance = theTolerance;
386 double Controls::LyingOnGeom::GetTolerance()
391 bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh* theMeshDS,
392 const TopoDS_Shape& theShape,
393 const SMDS_MeshElement* theElem,
394 TopAbs_ShapeEnum theFindShapeEnum,
395 TopAbs_ShapeEnum theAvoidShapeEnum )
397 if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
400 TopTools_IndexedMapOfShape aSubShapes;
401 TopExp::MapShapes( theShape, aSubShapes );
403 for (int i = 1; i <= aSubShapes.Extent(); i++)
405 const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
407 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
408 if( aSubMesh->Contains( theElem ) )
411 SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
412 while ( aNodeIt->more() )
414 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
415 SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
416 while ( anElemIt->more() )
418 const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
419 if (anElement == theElem)
435 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
437 SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
438 return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
443 toArray( const TColStd_ListOfInteger& aList )
445 SMESH::long_array_var anArray = new SMESH::long_array;
446 anArray->length( aList.Extent() );
447 TColStd_ListIteratorOfListOfInteger anIter( aList );
449 for( ; anIter.More(); anIter.Next() )
450 anArray[ i++ ] = anIter.Value();
452 return anArray._retn();
457 toArray( const TColStd_ListOfReal& aList )
459 SMESH::double_array_var anArray = new SMESH::double_array;
460 anArray->length( aList.Extent() );
461 TColStd_ListIteratorOfListOfReal anIter( aList );
463 for( ; anIter.More(); anIter.Next() )
464 anArray[ i++ ] = anIter.Value();
466 return anArray._retn();
469 static SMESH::Filter::Criterion createCriterion()
471 SMESH::Filter::Criterion aCriterion;
473 aCriterion.Type = FT_Undefined;
474 aCriterion.Compare = FT_Undefined;
475 aCriterion.Threshold = 0;
476 aCriterion.UnaryOp = FT_Undefined;
477 aCriterion.BinaryOp = FT_Undefined;
478 aCriterion.ThresholdStr = "";
479 aCriterion.ThresholdID = "";
480 aCriterion.Tolerance = Precision::Confusion();
481 aCriterion.TypeOfElement = SMESH::ALL;
482 aCriterion.Precision = -1;
487 static TopoDS_Shape getShapeByName( const char* theName )
491 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
492 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
493 if (!CORBA::is_nil(aStudy))
495 SALOMEDS::Study::ListOfSObject_var aList =
496 aStudy->FindObjectByName( theName, "GEOM" );
497 if ( aList->length() > 0 )
499 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
500 if ( !aGeomObj->_is_nil() )
502 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
503 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
509 return TopoDS_Shape();
512 static TopoDS_Shape getShapeByID (const char* theID)
514 if (theID != 0 && theID != "") {
515 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
516 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
518 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
519 SALOMEDS::GenericAttribute_var anAttr;
520 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
521 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
522 CORBA::String_var aVal = anIOR->Value();
523 CORBA::Object_var obj = aStudy->ConvertIORToObject(aVal);
524 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
526 if (!aGeomObj->_is_nil()) {
527 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
528 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
534 return TopoDS_Shape();
537 static char* getShapeNameByID (const char* theID)
539 char* aName = (char*)"";
541 if (theID != 0 && theID != "") {
542 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
543 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
545 //SALOMEDS::SObject_var aSObj = aStudy->FindObjectIOR( theID );
546 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
547 SALOMEDS::GenericAttribute_var anAttr;
548 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeName")) {
549 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
550 aName = aNameAttr->Value();
564 Description : An abstact class for all functors
566 Functor_i::Functor_i():
567 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
569 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
570 //PortableServer::ObjectId_var anObjectId =
571 // SMESH_Gen_i::GetPOA()->activate_object( this );
574 Functor_i::~Functor_i()
576 //TPythonDump()<<this<<".Destroy()";
579 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
581 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
582 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
585 ElementType Functor_i::GetElementType()
587 return ( ElementType )myFunctorPtr->GetType();
592 Class : NumericalFunctor_i
593 Description : Base class for numerical functors
595 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
597 return myNumericalFunctorPtr->GetValue( theId );
600 SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals)
602 std::vector<int> nbEvents;
603 std::vector<double> funValues;
604 myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues);
606 nbIntervals = CORBA::Short( std::min( nbEvents.size(), funValues.size() - 1));
607 SMESH::Histogram_var histogram = new SMESH::Histogram;
608 if ( nbIntervals > 0 )
610 histogram->length( nbIntervals );
611 for ( int i = 0; i < nbIntervals; ++i )
613 HistogramRectangle& rect = histogram[i];
614 rect.nbEvents = nbEvents[i];
615 rect.min = funValues[i];
616 rect.max = funValues[i+1];
619 return histogram._retn();
622 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
624 myNumericalFunctorPtr->SetPrecision( thePrecision );
625 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
628 CORBA::Long NumericalFunctor_i::GetPrecision()
630 return myNumericalFunctorPtr->GetPrecision();
633 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
635 return myNumericalFunctorPtr;
640 Class : SMESH_MinimumAngle
641 Description : Functor for calculation of minimum angle
643 MinimumAngle_i::MinimumAngle_i()
645 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
646 myFunctorPtr = myNumericalFunctorPtr;
649 FunctorType MinimumAngle_i::GetFunctorType()
651 return SMESH::FT_MinimumAngle;
657 Description : Functor for calculating aspect ratio
659 AspectRatio_i::AspectRatio_i()
661 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
662 myFunctorPtr = myNumericalFunctorPtr;
665 FunctorType AspectRatio_i::GetFunctorType()
667 return SMESH::FT_AspectRatio;
672 Class : AspectRatio3D
673 Description : Functor for calculating aspect ratio 3D
675 AspectRatio3D_i::AspectRatio3D_i()
677 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
678 myFunctorPtr = myNumericalFunctorPtr;
681 FunctorType AspectRatio3D_i::GetFunctorType()
683 return SMESH::FT_AspectRatio3D;
689 Description : Functor for calculating warping
691 Warping_i::Warping_i()
693 myNumericalFunctorPtr.reset( new Controls::Warping() );
694 myFunctorPtr = myNumericalFunctorPtr;
697 FunctorType Warping_i::GetFunctorType()
699 return SMESH::FT_Warping;
705 Description : Functor for calculating taper
709 myNumericalFunctorPtr.reset( new Controls::Taper() );
710 myFunctorPtr = myNumericalFunctorPtr;
713 FunctorType Taper_i::GetFunctorType()
715 return SMESH::FT_Taper;
721 Description : Functor for calculating skew in degrees
725 myNumericalFunctorPtr.reset( new Controls::Skew() );
726 myFunctorPtr = myNumericalFunctorPtr;
729 FunctorType Skew_i::GetFunctorType()
731 return SMESH::FT_Skew;
736 Description : Functor for calculating area
740 myNumericalFunctorPtr.reset( new Controls::Area() );
741 myFunctorPtr = myNumericalFunctorPtr;
744 FunctorType Area_i::GetFunctorType()
746 return SMESH::FT_Area;
751 Description : Functor for calculating volume of 3D element
753 Volume3D_i::Volume3D_i()
755 myNumericalFunctorPtr.reset( new Controls::Volume() );
756 myFunctorPtr = myNumericalFunctorPtr;
759 FunctorType Volume3D_i::GetFunctorType()
761 return SMESH::FT_Volume3D;
765 Class : MaxElementLength2D_i
766 Description : Functor for calculating maximum length of 2D element
768 MaxElementLength2D_i::MaxElementLength2D_i()
770 myNumericalFunctorPtr.reset( new Controls::MaxElementLength2D() );
771 myFunctorPtr = myNumericalFunctorPtr;
774 FunctorType MaxElementLength2D_i::GetFunctorType()
776 return SMESH::FT_MaxElementLength2D;
780 Class : MaxElementLength3D_i
781 Description : Functor for calculating maximum length of 3D element
783 MaxElementLength3D_i::MaxElementLength3D_i()
785 myNumericalFunctorPtr.reset( new Controls::MaxElementLength3D() );
786 myFunctorPtr = myNumericalFunctorPtr;
789 FunctorType MaxElementLength3D_i::GetFunctorType()
791 return SMESH::FT_MaxElementLength3D;
796 Description : Functor for calculating length off edge
800 myNumericalFunctorPtr.reset( new Controls::Length() );
801 myFunctorPtr = myNumericalFunctorPtr;
804 FunctorType Length_i::GetFunctorType()
806 return SMESH::FT_Length;
811 Description : Functor for calculating length of edge
813 Length2D_i::Length2D_i()
815 myNumericalFunctorPtr.reset( new Controls::Length2D() );
816 myFunctorPtr = myNumericalFunctorPtr;
819 FunctorType Length2D_i::GetFunctorType()
821 return SMESH::FT_Length2D;
824 SMESH::Length2D::Values* Length2D_i::GetValues()
826 INFOS("Length2D_i::GetValues");
827 SMESH::Controls::Length2D::TValues aValues;
828 (dynamic_cast<SMESH::Controls::Length2D*>(myFunctorPtr.get()))->GetValues( aValues );
830 long i = 0, iEnd = aValues.size();
832 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
833 aResult->length(iEnd);
835 SMESH::Controls::Length2D::TValues::const_iterator anIter;
836 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
838 const SMESH::Controls::Length2D::Value& aVal = *anIter;
839 SMESH::Length2D::Value &aValue = aResult[ i ];
841 aValue.myLength = aVal.myLength;
842 aValue.myPnt1 = aVal.myPntId[ 0 ];
843 aValue.myPnt2 = aVal.myPntId[ 1 ];
846 INFOS("Length2D_i::GetValuess~");
847 return aResult._retn();
851 Class : MultiConnection_i
852 Description : Functor for calculating number of faces conneted to the edge
854 MultiConnection_i::MultiConnection_i()
856 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
857 myFunctorPtr = myNumericalFunctorPtr;
860 FunctorType MultiConnection_i::GetFunctorType()
862 return SMESH::FT_MultiConnection;
866 Class : MultiConnection2D_i
867 Description : Functor for calculating number of faces conneted to the edge
869 MultiConnection2D_i::MultiConnection2D_i()
871 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
872 myFunctorPtr = myNumericalFunctorPtr;
875 FunctorType MultiConnection2D_i::GetFunctorType()
877 return SMESH::FT_MultiConnection2D;
880 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
882 INFOS("MultiConnection2D_i::GetValues");
883 SMESH::Controls::MultiConnection2D::MValues aValues;
884 (dynamic_cast<SMESH::Controls::MultiConnection2D*>(myFunctorPtr.get()))->GetValues( aValues );
886 long i = 0, iEnd = aValues.size();
888 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
889 aResult->length(iEnd);
891 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
892 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
894 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
895 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
897 aValue.myPnt1 = aVal.myPntId[ 0 ];
898 aValue.myPnt2 = aVal.myPntId[ 1 ];
899 aValue.myNbConnects = (*anIter).second;
902 INFOS("Multiconnection2D_i::GetValuess~");
903 return aResult._retn();
913 Description : Base class for all predicates
915 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
917 return myPredicatePtr->IsSatisfy( theId );
920 Controls::PredicatePtr Predicate_i::GetPredicate()
922 return myPredicatePtr;
926 Class : BadOrientedVolume_i
927 Description : Verify whether a mesh volume is incorrectly oriented from
928 the point of view of MED convention
930 BadOrientedVolume_i::BadOrientedVolume_i()
932 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
933 myFunctorPtr = myPredicatePtr = control;
936 FunctorType BadOrientedVolume_i::GetFunctorType()
938 return SMESH::FT_BadOrientedVolume;
942 Class : BareBorderVolume_i
943 Description : Verify whether a mesh volume is incorrectly oriented from
944 the point of view of MED convention
946 BareBorderVolume_i::BareBorderVolume_i()
948 Controls::PredicatePtr control( new Controls::BareBorderVolume() );
949 myFunctorPtr = myPredicatePtr = control;
952 FunctorType BareBorderVolume_i::GetFunctorType()
954 return SMESH::FT_BareBorderVolume;
958 Class : BareBorderFace_i
959 Description : Verify whether a mesh volume is incorrectly oriented from
960 the point of view of MED convention
962 BareBorderFace_i::BareBorderFace_i()
964 Controls::PredicatePtr control( new Controls::BareBorderFace() );
965 myFunctorPtr = myPredicatePtr = control;
968 FunctorType BareBorderFace_i::GetFunctorType()
970 return SMESH::FT_BareBorderFace;
974 Class : BelongToGeom_i
975 Description : Predicate for selection on geometrical support
977 BelongToGeom_i::BelongToGeom_i()
979 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
980 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
985 BelongToGeom_i::~BelongToGeom_i()
991 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
993 if ( theGeom->_is_nil() )
995 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
996 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
997 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
998 myBelongToGeomPtr->SetGeom( aLocShape );
999 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1002 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
1004 myBelongToGeomPtr->SetGeom( theShape );
1007 void BelongToGeom_i::SetElementType(ElementType theType){
1008 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
1009 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1012 FunctorType BelongToGeom_i::GetFunctorType()
1014 return SMESH::FT_BelongToGeom;
1017 void BelongToGeom_i::SetShapeName( const char* theName )
1020 myShapeName = strdup( theName );
1021 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1022 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1025 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
1028 myShapeName = strdup( theName );
1031 myShapeID = strdup( theID );
1035 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1036 myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
1038 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1041 char* BelongToGeom_i::GetShapeName()
1043 return CORBA::string_dup( myShapeName );
1046 char* BelongToGeom_i::GetShapeID()
1048 return CORBA::string_dup( myShapeID );
1051 void BelongToGeom_i::SetTolerance( CORBA::Double theToler )
1053 myBelongToGeomPtr->SetTolerance( theToler );
1054 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1057 CORBA::Double BelongToGeom_i::GetTolerance()
1059 return myBelongToGeomPtr->GetTolerance();
1063 Class : BelongToSurface_i
1064 Description : Predicate for selection on geometrical support
1066 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
1068 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
1069 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
1072 mySurfaceType = theSurfaceType;
1075 BelongToSurface_i::~BelongToSurface_i()
1081 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1083 if ( theGeom->_is_nil() )
1085 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1086 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1087 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1089 if ( aLocShape.ShapeType() == TopAbs_FACE )
1091 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
1092 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
1094 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1099 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
1102 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
1105 myShapeName = strdup( theName );
1106 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1107 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
1110 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
1113 myShapeName = strdup( theName );
1116 myShapeID = strdup( theID );
1120 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1121 myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
1123 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1126 char* BelongToSurface_i::GetShapeName()
1128 return CORBA::string_dup( myShapeName );
1131 char* BelongToSurface_i::GetShapeID()
1133 return CORBA::string_dup( myShapeID );
1136 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
1138 myElementsOnSurfacePtr->SetTolerance( theToler );
1139 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1142 CORBA::Double BelongToSurface_i::GetTolerance()
1144 return myElementsOnSurfacePtr->GetTolerance();
1147 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
1149 myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
1150 TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
1153 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
1155 return myElementsOnSurfacePtr->GetUseBoundaries();
1160 Class : BelongToPlane_i
1161 Description : Verify whether mesh element lie in pointed Geom planar object
1164 BelongToPlane_i::BelongToPlane_i()
1165 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
1169 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1171 BelongToSurface_i::SetSurface( theGeom, theType );
1172 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
1175 FunctorType BelongToPlane_i::GetFunctorType()
1177 return FT_BelongToPlane;
1181 Class : BelongToCylinder_i
1182 Description : Verify whether mesh element lie in pointed Geom planar object
1185 BelongToCylinder_i::BelongToCylinder_i()
1186 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1190 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1192 BelongToSurface_i::SetSurface( theGeom, theType );
1193 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
1196 FunctorType BelongToCylinder_i::GetFunctorType()
1198 return FT_BelongToCylinder;
1202 Class : BelongToGenSurface_i
1203 Description : Verify whether mesh element lie in pointed Geom planar object
1206 BelongToGenSurface_i::BelongToGenSurface_i()
1207 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1211 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1213 if ( theGeom->_is_nil() )
1215 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1216 if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1217 aLocShape.Nullify();
1219 BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1220 TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1223 FunctorType BelongToGenSurface_i::GetFunctorType()
1225 return FT_BelongToGenSurface;
1229 Class : LyingOnGeom_i
1230 Description : Predicate for selection on geometrical support
1232 LyingOnGeom_i::LyingOnGeom_i()
1234 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1235 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1240 LyingOnGeom_i::~LyingOnGeom_i()
1246 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1248 if ( theGeom->_is_nil() )
1250 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1251 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1252 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1253 myLyingOnGeomPtr->SetGeom( aLocShape );
1254 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1257 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1259 myLyingOnGeomPtr->SetGeom( theShape );
1262 void LyingOnGeom_i::SetElementType(ElementType theType){
1263 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1264 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1267 FunctorType LyingOnGeom_i::GetFunctorType()
1269 return SMESH::FT_LyingOnGeom;
1272 void LyingOnGeom_i::SetShapeName( const char* theName )
1275 myShapeName = strdup( theName );
1276 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1277 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1280 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1283 myShapeName = strdup( theName );
1286 myShapeID = strdup( theID );
1290 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1291 myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
1293 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1296 char* LyingOnGeom_i::GetShapeName()
1298 return CORBA::string_dup( myShapeName );
1301 char* LyingOnGeom_i::GetShapeID()
1303 return CORBA::string_dup( myShapeID );
1306 void LyingOnGeom_i::SetTolerance( CORBA::Double theToler )
1308 myLyingOnGeomPtr->SetTolerance( theToler );
1309 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1312 CORBA::Double LyingOnGeom_i::GetTolerance()
1314 return myLyingOnGeomPtr->GetTolerance();
1318 Class : FreeBorders_i
1319 Description : Predicate for free borders
1321 FreeBorders_i::FreeBorders_i()
1323 myPredicatePtr.reset(new Controls::FreeBorders());
1324 myFunctorPtr = myPredicatePtr;
1327 FunctorType FreeBorders_i::GetFunctorType()
1329 return SMESH::FT_FreeBorders;
1334 Description : Predicate for free borders
1336 FreeEdges_i::FreeEdges_i()
1337 : myFreeEdgesPtr( new Controls::FreeEdges() )
1339 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1342 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1344 INFOS("FreeEdges_i::GetBorders");
1345 SMESH::Controls::FreeEdges::TBorders aBorders;
1346 myFreeEdgesPtr->GetBoreders( aBorders );
1348 long i = 0, iEnd = aBorders.size();
1350 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1351 aResult->length(iEnd);
1353 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1354 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1356 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1357 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1359 aBorder.myElemId = aBord.myElemId;
1360 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1361 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1364 INFOS("FreeEdges_i::GetBorders~");
1365 return aResult._retn();
1368 FunctorType FreeEdges_i::GetFunctorType()
1370 return SMESH::FT_FreeEdges;
1375 Description : Predicate for free faces
1377 FreeFaces_i::FreeFaces_i()
1379 myPredicatePtr.reset(new Controls::FreeFaces());
1380 myFunctorPtr = myPredicatePtr;
1383 FunctorType FreeFaces_i::GetFunctorType()
1385 return SMESH::FT_FreeFaces;
1390 Description : Predicate for free nodes
1392 FreeNodes_i::FreeNodes_i()
1394 myPredicatePtr.reset(new Controls::FreeNodes());
1395 myFunctorPtr = myPredicatePtr;
1398 FunctorType FreeNodes_i::GetFunctorType()
1400 return SMESH::FT_FreeNodes;
1404 Class : RangeOfIds_i
1405 Description : Predicate for Range of Ids.
1406 Range may be specified with two ways.
1407 1. Using AddToRange method
1408 2. With SetRangeStr method. Parameter of this method is a string
1409 like as "1,2,3,50-60,63,67,70-"
1412 RangeOfIds_i::RangeOfIds_i()
1414 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1415 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1418 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1420 CORBA::Long iEnd = theIds.length();
1421 for ( CORBA::Long i = 0; i < iEnd; i++ )
1422 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1423 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1426 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1428 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1429 return myRangeOfIdsPtr->SetRangeStr(
1430 TCollection_AsciiString( (Standard_CString)theRange ) );
1433 char* RangeOfIds_i::GetRangeStr()
1435 TCollection_AsciiString aStr;
1436 myRangeOfIdsPtr->GetRangeStr( aStr );
1437 return CORBA::string_dup( aStr.ToCString() );
1440 void RangeOfIds_i::SetElementType( ElementType theType )
1442 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1443 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1446 FunctorType RangeOfIds_i::GetFunctorType()
1448 return SMESH::FT_RangeOfIds;
1452 Class : LinearOrQuadratic_i
1453 Description : Predicate to verify whether a mesh element is linear
1455 LinearOrQuadratic_i::LinearOrQuadratic_i()
1457 myLinearOrQuadraticPtr.reset(new Controls::LinearOrQuadratic());
1458 myFunctorPtr = myPredicatePtr = myLinearOrQuadraticPtr;
1461 void LinearOrQuadratic_i::SetElementType(ElementType theType)
1463 myLinearOrQuadraticPtr->SetType(SMDSAbs_ElementType(theType));
1464 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1467 FunctorType LinearOrQuadratic_i::GetFunctorType()
1469 return SMESH::FT_LinearOrQuadratic;
1473 Class : GroupColor_i
1474 Description : Functor for check color of group to whic mesh element belongs to
1476 GroupColor_i::GroupColor_i()
1478 myGroupColorPtr.reset(new Controls::GroupColor());
1479 myFunctorPtr = myPredicatePtr = myGroupColorPtr;
1482 FunctorType GroupColor_i::GetFunctorType()
1484 return SMESH::FT_GroupColor;
1487 void GroupColor_i::SetColorStr( const char* theColor )
1489 myGroupColorPtr->SetColorStr(
1490 TCollection_AsciiString( (Standard_CString)theColor ) );
1491 TPythonDump()<<this<<".SetColorStr('"<<theColor<<"')";
1494 char* GroupColor_i::GetColorStr()
1496 TCollection_AsciiString aStr;
1497 myGroupColorPtr->GetColorStr( aStr );
1498 return CORBA::string_dup( aStr.ToCString() );
1501 void GroupColor_i::SetElementType(ElementType theType)
1503 myGroupColorPtr->SetType(SMDSAbs_ElementType(theType));
1504 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1508 Class : ElemGeomType_i
1509 Description : Predicate check is element has indicated geometry type
1511 ElemGeomType_i::ElemGeomType_i()
1513 myElemGeomTypePtr.reset(new Controls::ElemGeomType());
1514 myFunctorPtr = myPredicatePtr = myElemGeomTypePtr;
1517 void ElemGeomType_i::SetElementType(ElementType theType)
1519 myElemGeomTypePtr->SetType(SMDSAbs_ElementType(theType));
1520 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1523 void ElemGeomType_i::SetGeometryType(GeometryType theType)
1525 myElemGeomTypePtr->SetGeomType(SMDSAbs_GeometryType(theType));
1526 TPythonDump()<<this<<".SetGeometryType("<<theType<<")";
1529 GeometryType ElemGeomType_i::GetGeometryType() const
1531 return (GeometryType)myElemGeomTypePtr->GetGeomType();;
1534 FunctorType ElemGeomType_i::GetFunctorType()
1536 return SMESH::FT_ElemGeomType;
1540 Class : Comparator_i
1541 Description : Base class for comparators
1543 Comparator_i::Comparator_i():
1544 myNumericalFunctor( NULL )
1547 Comparator_i::~Comparator_i()
1549 if ( myNumericalFunctor )
1550 myNumericalFunctor->Destroy();
1553 void Comparator_i::SetMargin( CORBA::Double theValue )
1555 myComparatorPtr->SetMargin( theValue );
1556 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1559 CORBA::Double Comparator_i::GetMargin()
1561 return myComparatorPtr->GetMargin();
1564 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1566 if ( myNumericalFunctor )
1567 myNumericalFunctor->Destroy();
1569 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1571 if ( myNumericalFunctor )
1573 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1574 myNumericalFunctor->Register();
1575 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1579 Controls::ComparatorPtr Comparator_i::GetComparator()
1581 return myComparatorPtr;
1584 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1586 return myNumericalFunctor;
1592 Description : Comparator "<"
1594 LessThan_i::LessThan_i()
1596 myComparatorPtr.reset( new Controls::LessThan() );
1597 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1600 FunctorType LessThan_i::GetFunctorType()
1602 return SMESH::FT_LessThan;
1608 Description : Comparator ">"
1610 MoreThan_i::MoreThan_i()
1612 myComparatorPtr.reset( new Controls::MoreThan() );
1613 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1616 FunctorType MoreThan_i::GetFunctorType()
1618 return SMESH::FT_MoreThan;
1624 Description : Comparator "="
1626 EqualTo_i::EqualTo_i()
1627 : myEqualToPtr( new Controls::EqualTo() )
1629 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1632 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1634 myEqualToPtr->SetTolerance( theToler );
1635 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1638 CORBA::Double EqualTo_i::GetTolerance()
1640 return myEqualToPtr->GetTolerance();
1643 FunctorType EqualTo_i::GetFunctorType()
1645 return SMESH::FT_EqualTo;
1649 Class : LogicalNOT_i
1650 Description : Logical NOT predicate
1652 LogicalNOT_i::LogicalNOT_i()
1653 : myPredicate( NULL ),
1654 myLogicalNOTPtr( new Controls::LogicalNOT() )
1656 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1659 LogicalNOT_i::~LogicalNOT_i()
1662 myPredicate->Destroy();
1665 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1668 myPredicate->Destroy();
1670 myPredicate = SMESH::GetPredicate(thePredicate);
1673 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1674 myPredicate->Register();
1675 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1679 FunctorType LogicalNOT_i::GetFunctorType()
1681 return SMESH::FT_LogicalNOT;
1684 Predicate_i* LogicalNOT_i::GetPredicate_i()
1691 Class : LogicalBinary_i
1692 Description : Base class for binary logical predicate
1694 LogicalBinary_i::LogicalBinary_i()
1695 : myPredicate1( NULL ),
1696 myPredicate2( NULL )
1699 LogicalBinary_i::~LogicalBinary_i()
1702 myPredicate1->Destroy();
1705 myPredicate2->Destroy();
1708 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1711 myPredicate1->SetMesh( theMesh );
1714 myPredicate2->SetMesh( theMesh );
1717 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1720 myPredicate1->Destroy();
1722 myPredicate1 = SMESH::GetPredicate(thePredicate);
1724 if ( myPredicate1 ){
1725 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1726 myPredicate1->Register();
1727 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1731 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1734 myPredicate2->Destroy();
1736 myPredicate2 = SMESH::GetPredicate(thePredicate);
1738 if ( myPredicate2 ){
1739 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1740 myPredicate2->Register();
1741 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1745 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1747 return myLogicalBinaryPtr;
1750 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1752 return myPredicate1;
1754 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1756 return myPredicate2;
1761 Class : LogicalAND_i
1762 Description : Logical AND
1764 LogicalAND_i::LogicalAND_i()
1766 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1767 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1770 FunctorType LogicalAND_i::GetFunctorType()
1772 return SMESH::FT_LogicalAND;
1778 Description : Logical OR
1780 LogicalOR_i::LogicalOR_i()
1782 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1783 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1786 FunctorType LogicalOR_i::GetFunctorType()
1788 return SMESH::FT_LogicalOR;
1796 FilterManager_i::FilterManager_i()
1797 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1799 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
1800 //PortableServer::ObjectId_var anObjectId =
1801 // SMESH_Gen_i::GetPOA()->activate_object( this );
1805 FilterManager_i::~FilterManager_i()
1807 //TPythonDump()<<this<<".Destroy()";
1811 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1813 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1814 SMESH::MinimumAngle_var anObj = aServant->_this();
1815 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1816 return anObj._retn();
1820 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1822 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1823 SMESH::AspectRatio_var anObj = aServant->_this();
1824 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1825 return anObj._retn();
1829 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1831 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1832 SMESH::AspectRatio3D_var anObj = aServant->_this();
1833 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1834 return anObj._retn();
1838 Warping_ptr FilterManager_i::CreateWarping()
1840 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1841 SMESH::Warping_var anObj = aServant->_this();
1842 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1843 return anObj._retn();
1847 Taper_ptr FilterManager_i::CreateTaper()
1849 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1850 SMESH::Taper_var anObj = aServant->_this();
1851 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1852 return anObj._retn();
1856 Skew_ptr FilterManager_i::CreateSkew()
1858 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1859 SMESH::Skew_var anObj = aServant->_this();
1860 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1861 return anObj._retn();
1865 Area_ptr FilterManager_i::CreateArea()
1867 SMESH::Area_i* aServant = new SMESH::Area_i();
1868 SMESH::Area_var anObj = aServant->_this();
1869 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1870 return anObj._retn();
1874 Volume3D_ptr FilterManager_i::CreateVolume3D()
1876 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
1877 SMESH::Volume3D_var anObj = aServant->_this();
1878 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
1879 return anObj._retn();
1883 MaxElementLength2D_ptr FilterManager_i::CreateMaxElementLength2D()
1885 SMESH::MaxElementLength2D_i* aServant = new SMESH::MaxElementLength2D_i();
1886 SMESH::MaxElementLength2D_var anObj = aServant->_this();
1887 TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength2D()";
1888 return anObj._retn();
1892 MaxElementLength3D_ptr FilterManager_i::CreateMaxElementLength3D()
1894 SMESH::MaxElementLength3D_i* aServant = new SMESH::MaxElementLength3D_i();
1895 SMESH::MaxElementLength3D_var anObj = aServant->_this();
1896 TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength3D()";
1897 return anObj._retn();
1901 Length_ptr FilterManager_i::CreateLength()
1903 SMESH::Length_i* aServant = new SMESH::Length_i();
1904 SMESH::Length_var anObj = aServant->_this();
1905 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1906 return anObj._retn();
1909 Length2D_ptr FilterManager_i::CreateLength2D()
1911 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1912 SMESH::Length2D_var anObj = aServant->_this();
1913 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1914 return anObj._retn();
1917 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1919 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1920 SMESH::MultiConnection_var anObj = aServant->_this();
1921 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1922 return anObj._retn();
1925 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1927 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1928 SMESH::MultiConnection2D_var anObj = aServant->_this();
1929 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
1930 return anObj._retn();
1933 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1935 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1936 SMESH::BelongToGeom_var anObj = aServant->_this();
1937 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
1938 return anObj._retn();
1941 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1943 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1944 SMESH::BelongToPlane_var anObj = aServant->_this();
1945 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
1946 return anObj._retn();
1949 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1951 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1952 SMESH::BelongToCylinder_var anObj = aServant->_this();
1953 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
1954 return anObj._retn();
1957 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
1959 SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
1960 SMESH::BelongToGenSurface_var anObj = aServant->_this();
1961 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
1962 return anObj._retn();
1965 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
1967 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
1968 SMESH::LyingOnGeom_var anObj = aServant->_this();
1969 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
1970 return anObj._retn();
1973 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1975 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1976 SMESH::FreeBorders_var anObj = aServant->_this();
1977 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
1978 return anObj._retn();
1981 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1983 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1984 SMESH::FreeEdges_var anObj = aServant->_this();
1985 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
1986 return anObj._retn();
1989 FreeFaces_ptr FilterManager_i::CreateFreeFaces()
1991 SMESH::FreeFaces_i* aServant = new SMESH::FreeFaces_i();
1992 SMESH::FreeFaces_var anObj = aServant->_this();
1993 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeFaces()";
1994 return anObj._retn();
1997 FreeNodes_ptr FilterManager_i::CreateFreeNodes()
1999 SMESH::FreeNodes_i* aServant = new SMESH::FreeNodes_i();
2000 SMESH::FreeNodes_var anObj = aServant->_this();
2001 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeNodes()";
2002 return anObj._retn();
2005 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
2007 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
2008 SMESH::RangeOfIds_var anObj = aServant->_this();
2009 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
2010 return anObj._retn();
2013 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
2015 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
2016 SMESH::BadOrientedVolume_var anObj = aServant->_this();
2017 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
2018 return anObj._retn();
2021 BareBorderVolume_ptr FilterManager_i::CreateBareBorderVolume()
2023 SMESH::BareBorderVolume_i* aServant = new SMESH::BareBorderVolume_i();
2024 SMESH::BareBorderVolume_var anObj = aServant->_this();
2025 TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderVolume()";
2026 return anObj._retn();
2029 BareBorderFace_ptr FilterManager_i::CreateBareBorderFace()
2031 SMESH::BareBorderFace_i* aServant = new SMESH::BareBorderFace_i();
2032 SMESH::BareBorderFace_var anObj = aServant->_this();
2033 TPythonDump()<<aServant<<" = "<<this<<".CreateBareBorderFace()";
2034 return anObj._retn();
2037 LessThan_ptr FilterManager_i::CreateLessThan()
2039 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
2040 SMESH::LessThan_var anObj = aServant->_this();
2041 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
2042 return anObj._retn();
2045 MoreThan_ptr FilterManager_i::CreateMoreThan()
2047 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
2048 SMESH::MoreThan_var anObj = aServant->_this();
2049 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
2050 return anObj._retn();
2053 EqualTo_ptr FilterManager_i::CreateEqualTo()
2055 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
2056 SMESH::EqualTo_var anObj = aServant->_this();
2057 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
2058 return anObj._retn();
2061 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
2063 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
2064 SMESH::LogicalNOT_var anObj = aServant->_this();
2065 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
2066 return anObj._retn();
2069 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
2071 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
2072 SMESH::LogicalAND_var anObj = aServant->_this();
2073 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
2074 return anObj._retn();
2077 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
2079 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
2080 SMESH::LogicalOR_var anObj = aServant->_this();
2081 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
2082 return anObj._retn();
2085 LinearOrQuadratic_ptr FilterManager_i::CreateLinearOrQuadratic()
2087 SMESH::LinearOrQuadratic_i* aServant = new SMESH::LinearOrQuadratic_i();
2088 SMESH::LinearOrQuadratic_var anObj = aServant->_this();
2089 TPythonDump()<<aServant<<" = "<<this<<".CreateLinearOrQuadratic()";
2090 return anObj._retn();
2093 GroupColor_ptr FilterManager_i::CreateGroupColor()
2095 SMESH::GroupColor_i* aServant = new SMESH::GroupColor_i();
2096 SMESH::GroupColor_var anObj = aServant->_this();
2097 TPythonDump()<<aServant<<" = "<<this<<".CreateGroupColor()";
2098 return anObj._retn();
2101 ElemGeomType_ptr FilterManager_i::CreateElemGeomType()
2103 SMESH::ElemGeomType_i* aServant = new SMESH::ElemGeomType_i();
2104 SMESH::ElemGeomType_var anObj = aServant->_this();
2105 TPythonDump()<<aServant<<" = "<<this<<".CreateElemGeomType()";
2106 return anObj._retn();
2109 Filter_ptr FilterManager_i::CreateFilter()
2111 SMESH::Filter_i* aServant = new SMESH::Filter_i();
2112 SMESH::Filter_var anObj = aServant->_this();
2113 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
2114 return anObj._retn();
2117 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
2119 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
2120 SMESH::FilterLibrary_var anObj = aServant->_this();
2121 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary('"<<aFileName<<"')";
2122 return anObj._retn();
2125 FilterLibrary_ptr FilterManager_i::CreateLibrary()
2127 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
2128 SMESH::FilterLibrary_var anObj = aServant->_this();
2129 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
2130 return anObj._retn();
2133 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
2135 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
2136 return remove( aFileName ) ? false : true;
2139 //=============================================================================
2141 * SMESH_Gen_i::CreateFilterManager
2143 * Create filter manager
2145 //=============================================================================
2147 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
2149 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2150 SMESH::FilterManager_var anObj = aFilter->_this();
2151 return anObj._retn();
2159 //=======================================================================
2160 // name : Filter_i::Filter_i
2161 // Purpose : Constructor
2162 //=======================================================================
2163 Filter_i::Filter_i()
2164 : myPredicate( NULL )
2167 //=======================================================================
2168 // name : Filter_i::~Filter_i
2169 // Purpose : Destructor
2170 //=======================================================================
2171 Filter_i::~Filter_i()
2174 myPredicate->Destroy();
2176 if(!CORBA::is_nil(myMesh))
2179 //TPythonDump()<<this<<".Destroy()";
2182 //=======================================================================
2183 // name : Filter_i::SetPredicate
2184 // Purpose : Set predicate
2185 //=======================================================================
2186 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
2189 myPredicate->Destroy();
2191 myPredicate = SMESH::GetPredicate(thePredicate);
2195 myFilter.SetPredicate( myPredicate->GetPredicate() );
2196 myPredicate->Register();
2197 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
2201 //=======================================================================
2202 // name : Filter_i::GetElementType
2203 // Purpose : Get entity type
2204 //=======================================================================
2205 SMESH::ElementType Filter_i::GetElementType()
2207 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
2210 //=======================================================================
2211 // name : Filter_i::SetMesh
2212 // Purpose : Set mesh
2213 //=======================================================================
2216 SetMesh( SMESH_Mesh_ptr theMesh )
2218 if(!CORBA::is_nil(theMesh))
2219 theMesh->Register();
2221 if(!CORBA::is_nil(myMesh))
2224 myMesh = SMESH_Mesh::_duplicate( theMesh );
2225 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
2232 return GetElementsId(myMesh);
2235 //=======================================================================
2236 // name : Filter_i::GetElementsId
2237 // Purpose : Get ids of entities
2238 //=======================================================================
2241 GetElementsId( Predicate_i* thePredicate,
2242 const SMDS_Mesh* theMesh,
2243 Controls::Filter::TIdSequence& theSequence )
2246 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
2251 GetElementsId( Predicate_i* thePredicate,
2252 SMESH_Mesh_ptr theMesh,
2253 Controls::Filter::TIdSequence& theSequence )
2256 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2257 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
2262 GetElementsId( SMESH_Mesh_ptr theMesh )
2264 SMESH::long_array_var anArray = new SMESH::long_array;
2265 if(!CORBA::is_nil(theMesh) && myPredicate){
2266 Controls::Filter::TIdSequence aSequence;
2267 GetElementsId(myPredicate,theMesh,aSequence);
2268 long i = 0, iEnd = aSequence.size();
2269 anArray->length( iEnd );
2270 for ( ; i < iEnd; i++ )
2271 anArray[ i ] = aSequence[i];
2273 return anArray._retn();
2276 template<class TElement, class TIterator, class TPredicate>
2277 static void collectMeshInfo(const TIterator& theItr,
2278 TPredicate& thePred,
2279 SMESH::long_array& theRes)
2283 while (theItr->more()) {
2284 const SMDS_MeshElement* anElem = theItr->next();
2285 if ( thePred->IsSatisfy( anElem->GetID() ) )
2286 theRes[ anElem->GetEntityType() ]++;
2290 //=============================================================================
2292 * \brief Returns statistic of mesh elements
2294 //=============================================================================
2295 SMESH::long_array* ::Filter_i::GetMeshInfo()
2297 SMESH::long_array_var aRes = new SMESH::long_array();
2298 aRes->length(SMESH::Entity_Last);
2299 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
2302 if(!CORBA::is_nil(myMesh) && myPredicate) {
2303 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2304 SMDS_ElemIteratorPtr it;
2305 switch( GetElementType() )
2308 collectMeshInfo<const SMDS_MeshNode*>(aMesh->nodesIterator(),myPredicate,aRes);
2311 collectMeshInfo<const SMDS_MeshElement*>(aMesh->edgesIterator(),myPredicate,aRes);
2314 collectMeshInfo<const SMDS_MeshElement*>(aMesh->facesIterator(),myPredicate,aRes);
2316 case SMDSAbs_Volume:
2317 collectMeshInfo<const SMDS_MeshElement*>(aMesh->volumesIterator(),myPredicate,aRes);
2321 collectMeshInfo<const SMDS_MeshElement*>(aMesh->elementsIterator(),myPredicate,aRes);
2327 return aRes._retn();
2330 //================================================================================
2332 * \brief Return GetElementType() within an array
2333 * Implement SMESH_IDSource interface
2335 //================================================================================
2337 SMESH::array_of_ElementType* Filter_i::GetTypes()
2339 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
2341 types[0] = GetElementType();
2342 return types._retn();
2345 //=======================================================================
2346 //function : GetMesh
2347 //purpose : Returns mesh
2348 //=======================================================================
2350 SMESH::SMESH_Mesh_ptr Filter_i::GetMesh()
2352 return SMESH_Mesh::_duplicate( myMesh );
2355 //=======================================================================
2356 // name : getCriteria
2357 // Purpose : Retrieve criterions from predicate
2358 //=======================================================================
2359 static inline bool getCriteria( Predicate_i* thePred,
2360 SMESH::Filter::Criteria_out theCriteria )
2362 int aFType = thePred->GetFunctorType();
2366 case FT_FreeBorders:
2369 case FT_LinearOrQuadratic:
2372 CORBA::ULong i = theCriteria->length();
2373 theCriteria->length( i + 1 );
2375 theCriteria[ i ] = createCriterion();
2377 theCriteria[ i ].Type = aFType;
2378 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
2381 case FT_BelongToGeom:
2383 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
2385 CORBA::ULong i = theCriteria->length();
2386 theCriteria->length( i + 1 );
2388 theCriteria[ i ] = createCriterion();
2390 theCriteria[ i ].Type = FT_BelongToGeom;
2391 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2392 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2393 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2394 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2398 case FT_BelongToPlane:
2399 case FT_BelongToCylinder:
2400 case FT_BelongToGenSurface:
2402 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
2404 CORBA::ULong i = theCriteria->length();
2405 theCriteria->length( i + 1 );
2407 theCriteria[ i ] = createCriterion();
2409 theCriteria[ i ].Type = aFType;
2410 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2411 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2412 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2413 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2417 case FT_LyingOnGeom:
2419 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
2421 CORBA::ULong i = theCriteria->length();
2422 theCriteria->length( i + 1 );
2424 theCriteria[ i ] = createCriterion();
2426 theCriteria[ i ].Type = FT_LyingOnGeom;
2427 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2428 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2429 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2430 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2436 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
2438 CORBA::ULong i = theCriteria->length();
2439 theCriteria->length( i + 1 );
2441 theCriteria[ i ] = createCriterion();
2443 theCriteria[ i ].Type = FT_RangeOfIds;
2444 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
2445 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2449 case FT_BadOrientedVolume:
2451 BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
2453 CORBA::ULong i = theCriteria->length();
2454 theCriteria->length( i + 1 );
2456 theCriteria[ i ] = createCriterion();
2458 theCriteria[ i ].Type = FT_BadOrientedVolume;
2459 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2463 case FT_BareBorderVolume:
2465 BareBorderVolume_i* aPred = dynamic_cast<BareBorderVolume_i*>( thePred );
2467 CORBA::ULong i = theCriteria->length();
2468 theCriteria->length( i + 1 );
2470 theCriteria[ i ] = createCriterion();
2472 theCriteria[ i ].Type = FT_BareBorderVolume;
2473 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2477 case FT_BareBorderFace:
2479 BareBorderFace_i* aPred = dynamic_cast<BareBorderFace_i*>( thePred );
2481 CORBA::ULong i = theCriteria->length();
2482 theCriteria->length( i + 1 );
2484 theCriteria[ i ] = createCriterion();
2486 theCriteria[ i ].Type = FT_BareBorderFace;
2487 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2495 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
2497 CORBA::ULong i = theCriteria->length();
2498 theCriteria->length( i + 1 );
2500 theCriteria[ i ] = createCriterion();
2502 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
2503 theCriteria[ i ].Compare = aFType;
2504 theCriteria[ i ].Threshold = aCompar->GetMargin();
2505 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
2507 if ( aFType == FT_EqualTo )
2509 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
2510 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
2517 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2518 getCriteria( aPred, theCriteria );
2519 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2526 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2527 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2528 if ( !getCriteria( aPred1, theCriteria ) )
2530 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2531 return getCriteria( aPred2, theCriteria );
2535 CORBA::ULong i = theCriteria->length();
2536 theCriteria->length( i + 1 );
2538 theCriteria[ i ] = createCriterion();
2540 GroupColor_i* aPred = dynamic_cast<GroupColor_i*>( thePred );
2541 theCriteria[ i ].Type = aFType;
2542 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2543 theCriteria[ i ].ThresholdStr = aPred->GetColorStr();
2547 case FT_ElemGeomType:
2549 CORBA::ULong i = theCriteria->length();
2550 theCriteria->length( i + 1 );
2552 theCriteria[ i ] = createCriterion();
2554 ElemGeomType_i* aPred = dynamic_cast<ElemGeomType_i*>( thePred );
2555 theCriteria[ i ].Type = aFType;
2556 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2557 theCriteria[ i ].Threshold = (double)aPred->GetGeometryType();
2568 //=======================================================================
2569 // name : Filter_i::GetCriteria
2570 // Purpose : Retrieve criterions from predicate
2571 //=======================================================================
2572 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2574 theCriteria = new SMESH::Filter::Criteria;
2575 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2578 //=======================================================================
2579 // name : Filter_i::SetCriteria
2580 // Purpose : Create new predicate and set criterions in it
2581 //=======================================================================
2582 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2584 if ( myPredicate != 0 )
2585 myPredicate->Destroy();
2587 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2588 FilterManager_ptr aFilterMgr = aFilter->_this();
2590 // CREATE two lists ( PREDICATES and LOG OP )
2593 TPythonDump()<<"aCriteria = []";
2594 std::list<SMESH::Predicate_ptr> aPredicates;
2595 std::list<int> aBinaries;
2596 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2598 int aCriterion = theCriteria[ i ].Type;
2599 int aCompare = theCriteria[ i ].Compare;
2600 double aThreshold = theCriteria[ i ].Threshold;
2601 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2602 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2603 int aUnary = theCriteria[ i ].UnaryOp;
2604 int aBinary = theCriteria[ i ].BinaryOp;
2605 double aTolerance = theCriteria[ i ].Tolerance;
2606 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
2607 long aPrecision = theCriteria[ i ].Precision;
2611 pd << "aCriterion = SMESH.Filter.Criterion(" << aCriterion << "," << aCompare
2612 << "," << aThreshold << ",'" << aThresholdStr;
2613 if (aThresholdID && strlen(aThresholdID))
2614 //pd << "',salome.ObjectToID(" << aThresholdID
2615 pd << "','" << aThresholdID
2616 << "'," << aUnary << "," << aBinary << "," << aTolerance
2617 << "," << aTypeOfElem << "," << aPrecision << ")";
2619 pd << "',''," << aUnary << "," << aBinary << "," << aTolerance
2620 << "," << aTypeOfElem << "," << aPrecision << ")";
2623 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2624 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2626 switch ( aCriterion )
2630 case SMESH::FT_MultiConnection:
2631 aFunctor = aFilterMgr->CreateMultiConnection();
2633 case SMESH::FT_MultiConnection2D:
2634 aFunctor = aFilterMgr->CreateMultiConnection2D();
2636 case SMESH::FT_Length:
2637 aFunctor = aFilterMgr->CreateLength();
2639 case SMESH::FT_Length2D:
2640 aFunctor = aFilterMgr->CreateLength2D();
2642 case SMESH::FT_AspectRatio:
2643 aFunctor = aFilterMgr->CreateAspectRatio();
2645 case SMESH::FT_AspectRatio3D:
2646 aFunctor = aFilterMgr->CreateAspectRatio3D();
2648 case SMESH::FT_Warping:
2649 aFunctor = aFilterMgr->CreateWarping();
2651 case SMESH::FT_MinimumAngle:
2652 aFunctor = aFilterMgr->CreateMinimumAngle();
2654 case SMESH::FT_Taper:
2655 aFunctor = aFilterMgr->CreateTaper();
2657 case SMESH::FT_Skew:
2658 aFunctor = aFilterMgr->CreateSkew();
2660 case SMESH::FT_Area:
2661 aFunctor = aFilterMgr->CreateArea();
2663 case SMESH::FT_Volume3D:
2664 aFunctor = aFilterMgr->CreateVolume3D();
2666 case SMESH::FT_MaxElementLength2D:
2667 aFunctor = aFilterMgr->CreateMaxElementLength2D();
2669 case SMESH::FT_MaxElementLength3D:
2670 aFunctor = aFilterMgr->CreateMaxElementLength3D();
2675 case SMESH::FT_FreeBorders:
2676 aPredicate = aFilterMgr->CreateFreeBorders();
2678 case SMESH::FT_FreeEdges:
2679 aPredicate = aFilterMgr->CreateFreeEdges();
2681 case SMESH::FT_FreeFaces:
2682 aPredicate = aFilterMgr->CreateFreeFaces();
2684 case SMESH::FT_FreeNodes:
2685 aPredicate = aFilterMgr->CreateFreeNodes();
2687 case SMESH::FT_BelongToGeom:
2689 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2690 tmpPred->SetElementType( aTypeOfElem );
2691 tmpPred->SetShape( aThresholdID, aThresholdStr );
2692 tmpPred->SetTolerance( aTolerance );
2693 aPredicate = tmpPred;
2696 case SMESH::FT_BelongToPlane:
2697 case SMESH::FT_BelongToCylinder:
2698 case SMESH::FT_BelongToGenSurface:
2700 SMESH::BelongToSurface_ptr tmpPred;
2701 switch ( aCriterion ) {
2702 case SMESH::FT_BelongToPlane:
2703 tmpPred = aFilterMgr->CreateBelongToPlane(); break;
2704 case SMESH::FT_BelongToCylinder:
2705 tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
2707 tmpPred = aFilterMgr->CreateBelongToGenSurface();
2709 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2710 tmpPred->SetTolerance( aTolerance );
2711 aPredicate = tmpPred;
2714 case SMESH::FT_LyingOnGeom:
2716 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2717 tmpPred->SetElementType( aTypeOfElem );
2718 tmpPred->SetShape( aThresholdID, aThresholdStr );
2719 tmpPred->SetTolerance( aTolerance );
2720 aPredicate = tmpPred;
2723 case SMESH::FT_RangeOfIds:
2725 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2726 tmpPred->SetRangeStr( aThresholdStr );
2727 tmpPred->SetElementType( aTypeOfElem );
2728 aPredicate = tmpPred;
2731 case SMESH::FT_BadOrientedVolume:
2733 aPredicate = aFilterMgr->CreateBadOrientedVolume();
2736 case SMESH::FT_BareBorderVolume:
2738 aPredicate = aFilterMgr->CreateBareBorderVolume();
2741 case SMESH::FT_BareBorderFace:
2743 aPredicate = aFilterMgr->CreateBareBorderFace();
2746 case SMESH::FT_LinearOrQuadratic:
2748 SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
2749 tmpPred->SetElementType( aTypeOfElem );
2750 aPredicate = tmpPred;
2753 case SMESH::FT_GroupColor:
2755 SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor();
2756 tmpPred->SetElementType( aTypeOfElem );
2757 tmpPred->SetColorStr( aThresholdStr );
2758 aPredicate = tmpPred;
2761 case SMESH::FT_ElemGeomType:
2763 SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType();
2764 tmpPred->SetElementType( aTypeOfElem );
2765 tmpPred->SetGeometryType( (GeometryType)(int)(aThreshold + 0.5) );
2766 aPredicate = tmpPred;
2775 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
2777 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
2779 if ( aCompare == SMESH::FT_LessThan )
2780 aComparator = aFilterMgr->CreateLessThan();
2781 else if ( aCompare == SMESH::FT_MoreThan )
2782 aComparator = aFilterMgr->CreateMoreThan();
2783 else if ( aCompare == SMESH::FT_EqualTo )
2784 aComparator = aFilterMgr->CreateEqualTo();
2788 aComparator->SetNumFunctor( aFunctor );
2789 aComparator->SetMargin( aThreshold );
2791 if ( aCompare == FT_EqualTo )
2793 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
2794 anEqualTo->SetTolerance( aTolerance );
2797 aPredicate = aComparator;
2799 aFunctor->SetPrecision( aPrecision );
2803 if ( aUnary == FT_LogicalNOT )
2805 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
2806 aNotPred->SetPredicate( aPredicate );
2807 aPredicate = aNotPred;
2811 aPredicates.push_back( aPredicate );
2812 aBinaries.push_back( aBinary );
2813 TPythonDump()<<"aCriteria.append(aCriterion)";
2816 TPythonDump()<<this<<".SetCriteria(aCriteria)";
2818 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
2820 // combine all "AND" operations
2822 std::list<SMESH::Predicate_ptr> aResList;
2824 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
2825 std::list<int>::iterator aBinaryIter;
2827 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
2828 int aPrevBinary = SMESH::FT_Undefined;
2830 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
2831 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
2832 ++aPredIter, ++aBinaryIter )
2834 int aCurrBinary = *aBinaryIter;
2836 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
2838 if ( aPrevBinary == SMESH::FT_LogicalAND )
2841 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2842 aBinaryPred->SetPredicate1( aPrevPredicate );
2843 aBinaryPred->SetPredicate2( *aPredIter );
2844 aCurrPred = aBinaryPred;
2847 aCurrPred = *aPredIter;
2849 if ( aCurrBinary != SMESH::FT_LogicalAND )
2850 aResList.push_back( aCurrPred );
2852 aPrevPredicate = aCurrPred;
2853 aPrevBinary = aCurrBinary;
2856 // combine all "OR" operations
2858 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2860 if ( aResList.size() == 1 )
2861 aResPredicate = *aResList.begin();
2862 else if ( aResList.size() > 1 )
2864 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2865 aResPredicate = *anIter;
2867 for ( ; anIter != aResList.end(); ++anIter )
2869 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2870 aBinaryPred->SetPredicate1( aResPredicate );
2871 aBinaryPred->SetPredicate2( *anIter );
2872 aResPredicate = aBinaryPred;
2876 SetPredicate( aResPredicate );
2878 return !aResPredicate->_is_nil();
2881 //=======================================================================
2882 // name : Filter_i::GetPredicate_i
2883 // Purpose : Get implementation of predicate
2884 //=======================================================================
2885 Predicate_i* Filter_i::GetPredicate_i()
2890 //=======================================================================
2891 // name : Filter_i::GetPredicate
2892 // Purpose : Get predicate
2893 //=======================================================================
2894 Predicate_ptr Filter_i::GetPredicate()
2896 if ( myPredicate == 0 )
2897 return SMESH::Predicate::_nil();
2900 SMESH::Predicate_var anObj = myPredicate->_this();
2901 return anObj._retn();
2909 #define ATTR_TYPE "type"
2910 #define ATTR_COMPARE "compare"
2911 #define ATTR_THRESHOLD "threshold"
2912 #define ATTR_UNARY "unary"
2913 #define ATTR_BINARY "binary"
2914 #define ATTR_THRESHOLD_STR "threshold_str"
2915 #define ATTR_TOLERANCE "tolerance"
2916 #define ATTR_ELEMENT_TYPE "ElementType"
2918 //=======================================================================
2920 // Purpose : Convert bool to LDOMString
2921 //=======================================================================
2922 static inline LDOMString toString( CORBA::Boolean val )
2924 return val ? "logical not" : "";
2927 //=======================================================================
2929 // Purpose : Convert LDOMString to bool
2930 //=======================================================================
2931 static inline bool toBool( const LDOMString& theStr )
2933 return theStr.equals( "logical not" );
2936 //=======================================================================
2938 // Purpose : Convert double to LDOMString
2939 //=======================================================================
2940 static inline LDOMString toString( CORBA::Double val )
2943 sprintf( a, "%e", val );
2944 return LDOMString( a );
2947 //=======================================================================
2949 // Purpose : Convert LDOMString to double
2950 //=======================================================================
2951 static inline double toDouble( const LDOMString& theStr )
2953 return atof( theStr.GetString() );
2956 //=======================================================================
2958 // Purpose : Convert functor type to LDOMString
2959 //=======================================================================
2960 static inline LDOMString toString( CORBA::Long theType )
2964 case FT_AspectRatio : return "Aspect ratio";
2965 case FT_Warping : return "Warping";
2966 case FT_MinimumAngle : return "Minimum angle";
2967 case FT_Taper : return "Taper";
2968 case FT_Skew : return "Skew";
2969 case FT_Area : return "Area";
2970 case FT_Volume3D : return "Volume3D";
2971 case FT_MaxElementLength2D: return "Max element length 2D";
2972 case FT_MaxElementLength3D: return "Max element length 3D";
2973 case FT_BelongToGeom : return "Belong to Geom";
2974 case FT_BelongToPlane : return "Belong to Plane";
2975 case FT_BelongToCylinder: return "Belong to Cylinder";
2976 case FT_BelongToGenSurface: return "Belong to Generic Surface";
2977 case FT_LyingOnGeom : return "Lying on Geom";
2978 case FT_BadOrientedVolume:return "Bad Oriented Volume";
2979 case FT_BareBorderVolume: return "Volumes with bare border";
2980 case FT_BareBorderFace : return "Faces with bare border";
2981 case FT_RangeOfIds : return "Range of IDs";
2982 case FT_FreeBorders : return "Free borders";
2983 case FT_FreeEdges : return "Free edges";
2984 case FT_FreeFaces : return "Free faces";
2985 case FT_FreeNodes : return "Free nodes";
2986 case FT_MultiConnection : return "Borders at multi-connections";
2987 case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2988 case FT_Length : return "Length";
2989 case FT_Length2D : return "Length 2D";
2990 case FT_LessThan : return "Less than";
2991 case FT_MoreThan : return "More than";
2992 case FT_EqualTo : return "Equal to";
2993 case FT_LogicalNOT : return "Not";
2994 case FT_LogicalAND : return "And";
2995 case FT_LogicalOR : return "Or";
2996 case FT_GroupColor : return "Color of Group";
2997 case FT_LinearOrQuadratic : return "Linear or Quadratic";
2998 case FT_ElemGeomType : return "Element geomtry type";
2999 case FT_Undefined : return "";
3000 default : return "";
3004 //=======================================================================
3005 // name : toFunctorType
3006 // Purpose : Convert LDOMString to functor type
3007 //=======================================================================
3008 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
3010 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
3011 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
3012 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
3013 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
3014 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
3015 else if ( theStr.equals( "Area" ) ) return FT_Area;
3016 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
3017 else if ( theStr.equals( "Max element length 2D" ) ) return FT_MaxElementLength2D;
3018 else if ( theStr.equals( "Max element length 3D" ) ) return FT_MaxElementLength3D;
3019 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
3020 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
3021 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
3022 else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface;
3023 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
3024 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
3025 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
3026 else if ( theStr.equals( "Free faces" ) ) return FT_FreeFaces;
3027 else if ( theStr.equals( "Free nodes" ) ) return FT_FreeNodes;
3028 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
3029 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
3030 else if ( theStr.equals( "Length" ) ) return FT_Length;
3031 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
3032 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
3033 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
3034 else if ( theStr.equals( "Volumes with bare border" ) ) return FT_BareBorderVolume;
3035 else if ( theStr.equals( "Faces with bare border" ) ) return FT_BareBorderFace;
3036 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
3037 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
3038 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
3039 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
3040 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
3041 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
3042 else if ( theStr.equals( "Color of Group" ) ) return FT_GroupColor;
3043 else if ( theStr.equals( "Linear or Quadratic" ) ) return FT_LinearOrQuadratic;
3044 else if ( theStr.equals( "Element geomtry type" ) ) return FT_ElemGeomType;
3045 else if ( theStr.equals( "" ) ) return FT_Undefined;
3046 else return FT_Undefined;
3049 //=======================================================================
3050 // name : toFunctorType
3051 // Purpose : Convert LDOMString to value of ElementType enumeration
3052 //=======================================================================
3053 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
3055 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
3056 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
3057 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
3058 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
3059 else return SMESH::ALL;
3062 //=======================================================================
3064 // Purpose : Convert ElementType to string
3065 //=======================================================================
3066 static inline LDOMString toString( const SMESH::ElementType theType )
3070 case SMESH::NODE : return "NODE";
3071 case SMESH::EDGE : return "EDGE";
3072 case SMESH::FACE : return "FACE";
3073 case SMESH::VOLUME : return "VOLUME";
3074 case SMESH::ALL : return "ALL";
3075 default : return "";
3079 //=======================================================================
3080 // name : findFilter
3081 // Purpose : Find filter in document
3082 //=======================================================================
3083 static LDOM_Element findFilter( const char* theFilterName,
3084 const LDOM_Document& theDoc,
3085 LDOM_Node* theParent = 0 )
3087 LDOM_Element aRootElement = theDoc.getDocumentElement();
3088 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
3089 return LDOM_Element();
3091 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
3092 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
3094 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
3095 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3097 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
3098 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
3099 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
3101 if ( theParent != 0 )
3102 *theParent = aTypeNode;
3103 return (LDOM_Element&)aFilter;
3107 return LDOM_Element();
3110 //=======================================================================
3111 // name : getSectionName
3112 // Purpose : Get name of section of filters
3113 //=======================================================================
3114 static const char* getSectionName( const ElementType theType )
3118 case SMESH::NODE : return "Filters for nodes";
3119 case SMESH::EDGE : return "Filters for edges";
3120 case SMESH::FACE : return "Filters for faces";
3121 case SMESH::VOLUME : return "Filters for volumes";
3122 case SMESH::ALL : return "Filters for elements";
3123 default : return "";
3127 //=======================================================================
3128 // name : getSection
3129 // Purpose : Create section for filters corresponding to the entity type
3130 //=======================================================================
3131 static LDOM_Node getSection( const ElementType theType,
3132 LDOM_Document& theDoc,
3133 const bool toCreate = false )
3135 LDOM_Element aRootElement = theDoc.getDocumentElement();
3136 if ( aRootElement.isNull() )
3140 bool anExist = false;
3141 const char* aSectionName = getSectionName( theType );
3142 if ( strcmp( aSectionName, "" ) == 0 )
3145 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
3147 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
3149 aNode = aSections.item( i );
3150 LDOM_Element& anItem = ( LDOM_Element& )aNode;
3151 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
3158 // Create new section if necessary
3163 LDOM_Element aNewItem = theDoc.createElement( "section" );
3164 aNewItem.setAttribute( "name", aSectionName );
3165 aRootElement.appendChild( aNewItem );
3175 //=======================================================================
3176 // name : createFilterItem
3177 // Purpose : Create filter item or LDOM document
3178 //=======================================================================
3179 static LDOM_Element createFilterItem( const char* theName,
3180 SMESH::Filter_ptr theFilter,
3181 LDOM_Document& theDoc )
3183 // create new filter in document
3184 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
3185 aFilterItem.setAttribute( "name", theName );
3187 // save filter criterions
3188 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3190 if ( !theFilter->GetCriteria( aCriteria ) )
3191 return LDOM_Element();
3193 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
3195 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
3197 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
3198 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
3199 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
3200 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
3201 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
3203 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
3204 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
3205 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
3206 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
3208 aFilterItem.appendChild( aCriterionItem );
3214 //=======================================================================
3215 // name : FilterLibrary_i::FilterLibrary_i
3216 // Purpose : Constructor
3217 //=======================================================================
3218 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
3220 myFileName = strdup( theFileName );
3221 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
3222 myFilterMgr = aFilterMgr->_this();
3226 // Try to use existing library file
3227 bool anExists = false;
3228 if ( !aParser.parse( myFileName ) )
3230 myDoc = aParser.getDocument();
3233 // Create a new XML document if it doesn't exist
3235 myDoc = LDOM_Document::createDocument( LDOMString() );
3237 LDOM_Element aRootElement = myDoc.getDocumentElement();
3238 if ( aRootElement.isNull() )
3240 // If the existing document is empty --> try to create a new one
3242 myDoc = LDOM_Document::createDocument( LDOMString() );
3246 //=======================================================================
3247 // name : FilterLibrary_i::FilterLibrary_i
3248 // Purpose : Constructor
3249 //=======================================================================
3250 FilterLibrary_i::FilterLibrary_i()
3253 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
3254 myFilterMgr = aFilter->_this();
3256 myDoc = LDOM_Document::createDocument( LDOMString() );
3259 FilterLibrary_i::~FilterLibrary_i()
3262 //TPythonDump()<<this<<".Destroy()";
3265 //=======================================================================
3266 // name : FilterLibrary_i::Copy
3267 // Purpose : Create filter and initialize it with values from library
3268 //=======================================================================
3269 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
3271 Filter_ptr aRes = Filter::_nil();
3272 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
3274 if ( aFilter.isNull() )
3277 std::list<SMESH::Filter::Criterion> aCriteria;
3279 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
3280 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
3282 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
3284 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
3285 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
3286 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
3287 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
3288 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
3290 SMESH::Filter::Criterion aCriterion = createCriterion();
3292 aCriterion.Type = toFunctorType( aTypeStr );
3293 aCriterion.Compare = toFunctorType( aCompareStr );
3294 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
3295 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
3297 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
3299 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
3301 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3302 ? val : atof( str.GetString() );
3304 str = aCrit->getAttribute( ATTR_TOLERANCE );
3305 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3306 ? val : atof( str.GetString() );
3308 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
3309 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
3312 sprintf( a, "%d", val );
3313 aCriterion.ThresholdStr = strdup( a );
3316 aCriterion.ThresholdStr = str.GetString();
3318 aCriteria.push_back( aCriterion );
3321 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
3322 aCriteriaVar->length( aCriteria.size() );
3325 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
3327 for( ; anIter != aCriteria.end(); ++anIter )
3328 aCriteriaVar[ i++ ] = *anIter;
3330 aRes = myFilterMgr->CreateFilter();
3331 aRes->SetCriteria( aCriteriaVar.inout() );
3333 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
3338 //=======================================================================
3339 // name : FilterLibrary_i::SetFileName
3340 // Purpose : Set file name for library
3341 //=======================================================================
3342 void FilterLibrary_i::SetFileName( const char* theFileName )
3345 myFileName = strdup( theFileName );
3346 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
3349 //=======================================================================
3350 // name : FilterLibrary_i::GetFileName
3351 // Purpose : Get file name of library
3352 //=======================================================================
3353 char* FilterLibrary_i::GetFileName()
3355 return CORBA::string_dup( myFileName );
3358 //=======================================================================
3359 // name : FilterLibrary_i::Add
3360 // Purpose : Add new filter to library
3361 //=======================================================================
3362 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
3364 // if filter already in library or entry filter is null do nothing
3365 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3366 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
3369 // get section corresponding to the filter type
3370 ElementType anEntType = theFilter->GetElementType();
3372 LDOM_Node aSection = getSection( anEntType, myDoc, true );
3373 if ( aSection.isNull() )
3376 // create filter item
3377 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
3378 if ( aFilterItem.isNull() )
3382 aSection.appendChild( aFilterItem );
3383 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3384 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
3389 //=======================================================================
3390 // name : FilterLibrary_i::Add
3391 // Purpose : Add new filter to library
3392 //=======================================================================
3393 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
3395 // if filter already in library or entry filter is null do nothing
3396 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3397 if ( !aFilterNode.isNull() )
3400 LDOM_Node aSection = getSection( theType, myDoc, true );
3401 if ( aSection.isNull() )
3404 // create filter item
3405 Filter_var aFilter = myFilterMgr->CreateFilter();
3407 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
3408 if ( aFilterItem.isNull() )
3412 aSection.appendChild( aFilterItem );
3413 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
3418 //=======================================================================
3419 // name : FilterLibrary_i::Delete
3420 // Purpose : Delete filter from library
3421 //=======================================================================
3422 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
3424 LDOM_Node aParentNode;
3425 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
3426 if ( aFilterNode.isNull() || aParentNode.isNull() )
3429 aParentNode.removeChild( aFilterNode );
3430 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
3434 //=======================================================================
3435 // name : FilterLibrary_i::Replace
3436 // Purpose : Replace existing filter with entry filter.
3437 // IMPORTANT : If filter does not exist it is not created
3438 //=======================================================================
3439 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
3440 const char* theNewName,
3441 Filter_ptr theFilter )
3443 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
3444 if ( aFilterItem.isNull() || theFilter->_is_nil() )
3447 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
3448 if ( aNewItem.isNull() )
3452 aFilterItem.ReplaceElement( aNewItem );
3453 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3454 TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
3459 //=======================================================================
3460 // name : FilterLibrary_i::Save
3461 // Purpose : Save library on disk
3462 //=======================================================================
3463 CORBA::Boolean FilterLibrary_i::Save()
3465 if ( myFileName == 0 || strlen( myFileName ) == 0 )
3468 FILE* aOutFile = fopen( myFileName, "wt" );
3472 LDOM_XmlWriter aWriter( aOutFile );
3473 aWriter.SetIndentation( 2 );
3477 TPythonDump()<<this<<".Save()";
3481 //=======================================================================
3482 // name : FilterLibrary_i::SaveAs
3483 // Purpose : Save library on disk
3484 //=======================================================================
3485 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
3487 myFileName = strdup ( aFileName );
3488 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
3492 //=======================================================================
3493 // name : FilterLibrary_i::IsPresent
3494 // Purpose : Verify whether filter is in library
3495 //=======================================================================
3496 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
3498 return !findFilter( theFilterName, myDoc ).isNull();
3501 //=======================================================================
3502 // name : FilterLibrary_i::NbFilters
3503 // Purpose : Return amount of filters in library
3504 //=======================================================================
3505 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
3507 string_array_var aNames = GetNames( theType );
3508 return aNames->length();
3511 //=======================================================================
3512 // name : FilterLibrary_i::GetNames
3513 // Purpose : Get names of filters from library
3514 //=======================================================================
3515 string_array* FilterLibrary_i::GetNames( ElementType theType )
3517 string_array_var anArray = new string_array;
3518 TColStd_SequenceOfHAsciiString aSeq;
3520 LDOM_Node aSection = getSection( theType, myDoc, false );
3522 if ( !aSection.isNull() )
3524 for ( LDOM_Node aFilter = aSection.getFirstChild();
3525 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3527 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
3528 aSeq.Append( new TCollection_HAsciiString(
3529 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
3533 anArray->length( aSeq.Length() );
3534 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
3535 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
3537 return anArray._retn();
3540 //=======================================================================
3541 // name : FilterLibrary_i::GetAllNames
3542 // Purpose : Get names of filters from library
3543 //=======================================================================
3544 string_array* FilterLibrary_i::GetAllNames()
3546 string_array_var aResArray = new string_array;
3547 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
3549 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
3551 int aPrevLength = aResArray->length();
3552 aResArray->length( aPrevLength + aNames->length() );
3553 for ( int i = 0, n = aNames->length(); i < n; i++ )
3554 aResArray[ aPrevLength + i ] = aNames[ i ];
3557 return aResArray._retn();