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"
38 #include "SMESHDS_Mesh.hxx"
40 #include <BRep_Tool.hxx>
41 #include <Geom_CylindricalSurface.hxx>
42 #include <Geom_Plane.hxx>
43 #include <LDOMParser.hxx>
44 #include <LDOMString.hxx>
45 #include <LDOM_Document.hxx>
46 #include <LDOM_Element.hxx>
47 #include <LDOM_Node.hxx>
48 #include <LDOM_XmlWriter.hxx>
49 #include <Precision.hxx>
50 #include <TColStd_ListIteratorOfListOfInteger.hxx>
51 #include <TColStd_ListIteratorOfListOfReal.hxx>
52 #include <TColStd_ListOfInteger.hxx>
53 #include <TColStd_ListOfReal.hxx>
54 #include <TColStd_SequenceOfHAsciiString.hxx>
55 #include <TCollection_HAsciiString.hxx>
57 #include <TopExp_Explorer.hxx>
59 #include <TopoDS_Face.hxx>
60 #include <TopoDS_Shape.hxx>
61 #include <TopTools_IndexedMapOfShape.hxx>
63 using namespace SMESH;
64 using namespace SMESH::Controls;
70 GetPredicate( Predicate_ptr thePredicate )
72 return DownCast<Predicate_i*>(thePredicate);
79 Description : Predicate for verifying whether entity belongs to
80 specified geometrical support
83 Controls::BelongToGeom::BelongToGeom()
87 myTolerance(Precision::Confusion())
90 void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
92 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
96 void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
102 static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
103 const TopoDS_Shape& theShape)
105 if (theMap.Contains(theShape)) return true;
107 if (theShape.ShapeType() == TopAbs_COMPOUND ||
108 theShape.ShapeType() == TopAbs_COMPSOLID)
110 TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
111 for (; anIt.More(); anIt.Next())
113 if (!IsSubShape(theMap, anIt.Value())) {
123 void Controls::BelongToGeom::init()
125 if (!myMeshDS || myShape.IsNull()) return;
127 // is subshape of main shape?
128 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
129 if (aMainShape.IsNull()) {
130 myIsSubshape = false;
133 TopTools_IndexedMapOfShape aMap;
134 TopExp::MapShapes(aMainShape, aMap);
135 myIsSubshape = IsSubShape(aMap, myShape);
140 myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
141 myElementsOnShapePtr->SetTolerance(myTolerance);
142 myElementsOnShapePtr->SetAllNodes(true); // belong, while false means "lays on"
143 myElementsOnShapePtr->SetMesh(myMeshDS);
144 myElementsOnShapePtr->SetShape(myShape, myType);
148 static bool IsContains( const SMESHDS_Mesh* theMeshDS,
149 const TopoDS_Shape& theShape,
150 const SMDS_MeshElement* theElem,
151 TopAbs_ShapeEnum theFindShapeEnum,
152 TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE )
154 TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
156 while( anExp.More() )
158 const TopoDS_Shape& aShape = anExp.Current();
159 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
160 if( aSubMesh->Contains( theElem ) )
168 bool Controls::BelongToGeom::IsSatisfy (long theId)
170 if (myMeshDS == 0 || myShape.IsNull())
175 return myElementsOnShapePtr->IsSatisfy(theId);
179 if (myType == SMDSAbs_Node)
181 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
183 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
184 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
185 switch( aTypeOfPosition )
187 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
188 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
189 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
190 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
196 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
198 if( myType == SMDSAbs_All )
200 return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
201 IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
202 IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
203 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
205 else if( myType == anElem->GetType() )
209 case SMDSAbs_Edge : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
210 case SMDSAbs_Face : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
211 case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
212 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
221 void Controls::BelongToGeom::SetType (SMDSAbs_ElementType theType)
227 SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
232 TopoDS_Shape Controls::BelongToGeom::GetShape()
237 const SMESHDS_Mesh* Controls::BelongToGeom::GetMeshDS() const
242 void Controls::BelongToGeom::SetTolerance (double theTolerance)
244 myTolerance = theTolerance;
249 double Controls::BelongToGeom::GetTolerance()
256 Description : Predicate for verifying whether entiy lying or partially lying on
257 specified geometrical support
260 Controls::LyingOnGeom::LyingOnGeom()
264 myTolerance(Precision::Confusion())
267 void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
269 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
273 void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
279 void Controls::LyingOnGeom::init()
281 if (!myMeshDS || myShape.IsNull()) return;
283 // is subshape of main shape?
284 TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
285 if (aMainShape.IsNull()) {
286 myIsSubshape = false;
289 TopTools_IndexedMapOfShape aMap;
290 TopExp::MapShapes(aMainShape, aMap);
291 myIsSubshape = IsSubShape(aMap, myShape);
296 myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
297 myElementsOnShapePtr->SetTolerance(myTolerance);
298 myElementsOnShapePtr->SetAllNodes(false); // lays on, while true means "belong"
299 myElementsOnShapePtr->SetMesh(myMeshDS);
300 myElementsOnShapePtr->SetShape(myShape, myType);
304 bool Controls::LyingOnGeom::IsSatisfy( long theId )
306 if ( myMeshDS == 0 || myShape.IsNull() )
311 return myElementsOnShapePtr->IsSatisfy(theId);
315 if( myType == SMDSAbs_Node )
317 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
319 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
320 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
321 switch( aTypeOfPosition )
323 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
324 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
325 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
326 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
332 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
334 if( myType == SMDSAbs_All )
336 return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
337 Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
338 Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
339 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
341 else if( myType == anElem->GetType() )
345 case SMDSAbs_Edge : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
346 case SMDSAbs_Face : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
347 case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
348 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
357 void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
363 SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
368 TopoDS_Shape Controls::LyingOnGeom::GetShape()
373 const SMESHDS_Mesh* Controls::LyingOnGeom::GetMeshDS() const
378 void Controls::LyingOnGeom::SetTolerance (double theTolerance)
380 myTolerance = theTolerance;
385 double Controls::LyingOnGeom::GetTolerance()
390 bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh* theMeshDS,
391 const TopoDS_Shape& theShape,
392 const SMDS_MeshElement* theElem,
393 TopAbs_ShapeEnum theFindShapeEnum,
394 TopAbs_ShapeEnum theAvoidShapeEnum )
396 if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
399 TopTools_IndexedMapOfShape aSubShapes;
400 TopExp::MapShapes( theShape, aSubShapes );
402 for (int i = 1; i <= aSubShapes.Extent(); i++)
404 const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
406 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
407 if( aSubMesh->Contains( theElem ) )
410 SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
411 while ( aNodeIt->more() )
413 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
414 SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
415 while ( anElemIt->more() )
417 const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
418 if (anElement == theElem)
434 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
436 SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
437 return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
442 toArray( const TColStd_ListOfInteger& aList )
444 SMESH::long_array_var anArray = new SMESH::long_array;
445 anArray->length( aList.Extent() );
446 TColStd_ListIteratorOfListOfInteger anIter( aList );
448 for( ; anIter.More(); anIter.Next() )
449 anArray[ i++ ] = anIter.Value();
451 return anArray._retn();
456 toArray( const TColStd_ListOfReal& aList )
458 SMESH::double_array_var anArray = new SMESH::double_array;
459 anArray->length( aList.Extent() );
460 TColStd_ListIteratorOfListOfReal anIter( aList );
462 for( ; anIter.More(); anIter.Next() )
463 anArray[ i++ ] = anIter.Value();
465 return anArray._retn();
468 static SMESH::Filter::Criterion createCriterion()
470 SMESH::Filter::Criterion aCriterion;
472 aCriterion.Type = FT_Undefined;
473 aCriterion.Compare = FT_Undefined;
474 aCriterion.Threshold = 0;
475 aCriterion.UnaryOp = FT_Undefined;
476 aCriterion.BinaryOp = FT_Undefined;
477 aCriterion.ThresholdStr = "";
478 aCriterion.ThresholdID = "";
479 aCriterion.Tolerance = Precision::Confusion();
480 aCriterion.TypeOfElement = SMESH::ALL;
481 aCriterion.Precision = -1;
486 static TopoDS_Shape getShapeByName( const char* theName )
490 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
491 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
492 if (!CORBA::is_nil(aStudy))
494 SALOMEDS::Study::ListOfSObject_var aList =
495 aStudy->FindObjectByName( theName, "GEOM" );
496 if ( aList->length() > 0 )
498 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
499 if ( !aGeomObj->_is_nil() )
501 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
502 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
508 return TopoDS_Shape();
511 static TopoDS_Shape getShapeByID (const char* theID)
513 if (theID != 0 && theID != "") {
514 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
515 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
517 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
518 SALOMEDS::GenericAttribute_var anAttr;
519 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
520 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
521 CORBA::String_var aVal = anIOR->Value();
522 CORBA::Object_var obj = aStudy->ConvertIORToObject(aVal);
523 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
525 if (!aGeomObj->_is_nil()) {
526 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
527 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
533 return TopoDS_Shape();
536 static char* getShapeNameByID (const char* theID)
538 char* aName = (char*)"";
540 if (theID != 0 && theID != "") {
541 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
542 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
544 //SALOMEDS::SObject_var aSObj = aStudy->FindObjectIOR( theID );
545 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
546 SALOMEDS::GenericAttribute_var anAttr;
547 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeName")) {
548 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
549 aName = aNameAttr->Value();
563 Description : An abstact class for all functors
565 Functor_i::Functor_i():
566 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
568 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
569 //PortableServer::ObjectId_var anObjectId =
570 // SMESH_Gen_i::GetPOA()->activate_object( this );
573 Functor_i::~Functor_i()
575 //TPythonDump()<<this<<".Destroy()";
578 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
580 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
581 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
584 ElementType Functor_i::GetElementType()
586 return ( ElementType )myFunctorPtr->GetType();
591 Class : NumericalFunctor_i
592 Description : Base class for numerical functors
594 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
596 return myNumericalFunctorPtr->GetValue( theId );
599 SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals)
601 std::vector<int> nbEvents;
602 std::vector<double> funValues;
603 myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues);
605 nbIntervals = CORBA::Short( std::min( nbEvents.size(), funValues.size() - 1));
606 SMESH::Histogram_var histogram = new SMESH::Histogram;
607 if ( nbIntervals > 0 )
609 histogram->length( nbIntervals );
610 for ( int i = 0; i < nbIntervals; ++i )
612 HistogramRectangle& rect = histogram[i];
613 rect.nbEvents = nbEvents[i];
614 rect.min = funValues[i];
615 rect.max = funValues[i+1];
618 return histogram._retn();
621 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
623 myNumericalFunctorPtr->SetPrecision( thePrecision );
624 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
627 CORBA::Long NumericalFunctor_i::GetPrecision()
629 return myNumericalFunctorPtr->GetPrecision();
632 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
634 return myNumericalFunctorPtr;
639 Class : SMESH_MinimumAngle
640 Description : Functor for calculation of minimum angle
642 MinimumAngle_i::MinimumAngle_i()
644 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
645 myFunctorPtr = myNumericalFunctorPtr;
648 FunctorType MinimumAngle_i::GetFunctorType()
650 return SMESH::FT_MinimumAngle;
656 Description : Functor for calculating aspect ratio
658 AspectRatio_i::AspectRatio_i()
660 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
661 myFunctorPtr = myNumericalFunctorPtr;
664 FunctorType AspectRatio_i::GetFunctorType()
666 return SMESH::FT_AspectRatio;
671 Class : AspectRatio3D
672 Description : Functor for calculating aspect ratio 3D
674 AspectRatio3D_i::AspectRatio3D_i()
676 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
677 myFunctorPtr = myNumericalFunctorPtr;
680 FunctorType AspectRatio3D_i::GetFunctorType()
682 return SMESH::FT_AspectRatio3D;
688 Description : Functor for calculating warping
690 Warping_i::Warping_i()
692 myNumericalFunctorPtr.reset( new Controls::Warping() );
693 myFunctorPtr = myNumericalFunctorPtr;
696 FunctorType Warping_i::GetFunctorType()
698 return SMESH::FT_Warping;
704 Description : Functor for calculating taper
708 myNumericalFunctorPtr.reset( new Controls::Taper() );
709 myFunctorPtr = myNumericalFunctorPtr;
712 FunctorType Taper_i::GetFunctorType()
714 return SMESH::FT_Taper;
720 Description : Functor for calculating skew in degrees
724 myNumericalFunctorPtr.reset( new Controls::Skew() );
725 myFunctorPtr = myNumericalFunctorPtr;
728 FunctorType Skew_i::GetFunctorType()
730 return SMESH::FT_Skew;
735 Description : Functor for calculating area
739 myNumericalFunctorPtr.reset( new Controls::Area() );
740 myFunctorPtr = myNumericalFunctorPtr;
743 FunctorType Area_i::GetFunctorType()
745 return SMESH::FT_Area;
750 Description : Functor for calculating volume of 3D element
752 Volume3D_i::Volume3D_i()
754 myNumericalFunctorPtr.reset( new Controls::Volume() );
755 myFunctorPtr = myNumericalFunctorPtr;
758 FunctorType Volume3D_i::GetFunctorType()
760 return SMESH::FT_Volume3D;
764 Class : MaxElementLength2D_i
765 Description : Functor for calculating maximum length of 2D element
767 MaxElementLength2D_i::MaxElementLength2D_i()
769 myNumericalFunctorPtr.reset( new Controls::MaxElementLength2D() );
770 myFunctorPtr = myNumericalFunctorPtr;
773 FunctorType MaxElementLength2D_i::GetFunctorType()
775 return SMESH::FT_MaxElementLength2D;
779 Class : MaxElementLength3D_i
780 Description : Functor for calculating maximum length of 3D element
782 MaxElementLength3D_i::MaxElementLength3D_i()
784 myNumericalFunctorPtr.reset( new Controls::MaxElementLength3D() );
785 myFunctorPtr = myNumericalFunctorPtr;
788 FunctorType MaxElementLength3D_i::GetFunctorType()
790 return SMESH::FT_MaxElementLength3D;
795 Description : Functor for calculating length off edge
799 myNumericalFunctorPtr.reset( new Controls::Length() );
800 myFunctorPtr = myNumericalFunctorPtr;
803 FunctorType Length_i::GetFunctorType()
805 return SMESH::FT_Length;
810 Description : Functor for calculating length of edge
812 Length2D_i::Length2D_i()
814 myNumericalFunctorPtr.reset( new Controls::Length2D() );
815 myFunctorPtr = myNumericalFunctorPtr;
818 FunctorType Length2D_i::GetFunctorType()
820 return SMESH::FT_Length2D;
823 SMESH::Length2D::Values* Length2D_i::GetValues()
825 INFOS("Length2D_i::GetValues");
826 SMESH::Controls::Length2D::TValues aValues;
827 (dynamic_cast<SMESH::Controls::Length2D*>(myFunctorPtr.get()))->GetValues( aValues );
829 long i = 0, iEnd = aValues.size();
831 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
832 aResult->length(iEnd);
834 SMESH::Controls::Length2D::TValues::const_iterator anIter;
835 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
837 const SMESH::Controls::Length2D::Value& aVal = *anIter;
838 SMESH::Length2D::Value &aValue = aResult[ i ];
840 aValue.myLength = aVal.myLength;
841 aValue.myPnt1 = aVal.myPntId[ 0 ];
842 aValue.myPnt2 = aVal.myPntId[ 1 ];
845 INFOS("Length2D_i::GetValuess~");
846 return aResult._retn();
850 Class : MultiConnection_i
851 Description : Functor for calculating number of faces conneted to the edge
853 MultiConnection_i::MultiConnection_i()
855 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
856 myFunctorPtr = myNumericalFunctorPtr;
859 FunctorType MultiConnection_i::GetFunctorType()
861 return SMESH::FT_MultiConnection;
865 Class : MultiConnection2D_i
866 Description : Functor for calculating number of faces conneted to the edge
868 MultiConnection2D_i::MultiConnection2D_i()
870 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
871 myFunctorPtr = myNumericalFunctorPtr;
874 FunctorType MultiConnection2D_i::GetFunctorType()
876 return SMESH::FT_MultiConnection2D;
879 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
881 INFOS("MultiConnection2D_i::GetValues");
882 SMESH::Controls::MultiConnection2D::MValues aValues;
883 (dynamic_cast<SMESH::Controls::MultiConnection2D*>(myFunctorPtr.get()))->GetValues( aValues );
885 long i = 0, iEnd = aValues.size();
887 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
888 aResult->length(iEnd);
890 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
891 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
893 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
894 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
896 aValue.myPnt1 = aVal.myPntId[ 0 ];
897 aValue.myPnt2 = aVal.myPntId[ 1 ];
898 aValue.myNbConnects = (*anIter).second;
901 INFOS("Multiconnection2D_i::GetValuess~");
902 return aResult._retn();
912 Description : Base class for all predicates
914 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
916 return myPredicatePtr->IsSatisfy( theId );
919 Controls::PredicatePtr Predicate_i::GetPredicate()
921 return myPredicatePtr;
925 Class : BadOrientedVolume_i
926 Description : Verify whether a mesh volume is incorrectly oriented from
927 the point of view of MED convention
929 BadOrientedVolume_i::BadOrientedVolume_i()
931 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
932 myFunctorPtr = myPredicatePtr = control;
935 FunctorType BadOrientedVolume_i::GetFunctorType()
937 return SMESH::FT_BadOrientedVolume;
941 Class : BelongToGeom_i
942 Description : Predicate for selection on geometrical support
944 BelongToGeom_i::BelongToGeom_i()
946 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
947 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
952 BelongToGeom_i::~BelongToGeom_i()
958 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
960 if ( theGeom->_is_nil() )
962 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
963 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
964 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
965 myBelongToGeomPtr->SetGeom( aLocShape );
966 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
969 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
971 myBelongToGeomPtr->SetGeom( theShape );
974 void BelongToGeom_i::SetElementType(ElementType theType){
975 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
976 TPythonDump()<<this<<".SetElementType("<<theType<<")";
979 FunctorType BelongToGeom_i::GetFunctorType()
981 return SMESH::FT_BelongToGeom;
984 void BelongToGeom_i::SetShapeName( const char* theName )
987 myShapeName = strdup( theName );
988 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
989 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
992 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
995 myShapeName = strdup( theName );
998 myShapeID = strdup( theID );
1002 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1003 myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
1005 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1008 char* BelongToGeom_i::GetShapeName()
1010 return CORBA::string_dup( myShapeName );
1013 char* BelongToGeom_i::GetShapeID()
1015 return CORBA::string_dup( myShapeID );
1018 void BelongToGeom_i::SetTolerance( CORBA::Double theToler )
1020 myBelongToGeomPtr->SetTolerance( theToler );
1021 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1024 CORBA::Double BelongToGeom_i::GetTolerance()
1026 return myBelongToGeomPtr->GetTolerance();
1030 Class : BelongToSurface_i
1031 Description : Predicate for selection on geometrical support
1033 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
1035 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
1036 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
1039 mySurfaceType = theSurfaceType;
1042 BelongToSurface_i::~BelongToSurface_i()
1048 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1050 if ( theGeom->_is_nil() )
1052 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1053 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1054 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1056 if ( aLocShape.ShapeType() == TopAbs_FACE )
1058 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
1059 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
1061 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1066 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
1069 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
1072 myShapeName = strdup( theName );
1073 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1074 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
1077 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
1080 myShapeName = strdup( theName );
1083 myShapeID = strdup( theID );
1087 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1088 myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
1090 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
1093 char* BelongToSurface_i::GetShapeName()
1095 return CORBA::string_dup( myShapeName );
1098 char* BelongToSurface_i::GetShapeID()
1100 return CORBA::string_dup( myShapeID );
1103 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
1105 myElementsOnSurfacePtr->SetTolerance( theToler );
1106 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1109 CORBA::Double BelongToSurface_i::GetTolerance()
1111 return myElementsOnSurfacePtr->GetTolerance();
1114 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
1116 myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
1117 TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
1120 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
1122 return myElementsOnSurfacePtr->GetUseBoundaries();
1127 Class : BelongToPlane_i
1128 Description : Verify whether mesh element lie in pointed Geom planar object
1131 BelongToPlane_i::BelongToPlane_i()
1132 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
1136 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1138 BelongToSurface_i::SetSurface( theGeom, theType );
1139 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
1142 FunctorType BelongToPlane_i::GetFunctorType()
1144 return FT_BelongToPlane;
1148 Class : BelongToCylinder_i
1149 Description : Verify whether mesh element lie in pointed Geom planar object
1152 BelongToCylinder_i::BelongToCylinder_i()
1153 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1157 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1159 BelongToSurface_i::SetSurface( theGeom, theType );
1160 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
1163 FunctorType BelongToCylinder_i::GetFunctorType()
1165 return FT_BelongToCylinder;
1169 Class : BelongToGenSurface_i
1170 Description : Verify whether mesh element lie in pointed Geom planar object
1173 BelongToGenSurface_i::BelongToGenSurface_i()
1174 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
1178 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
1180 if ( theGeom->_is_nil() )
1182 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1183 if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1184 aLocShape.Nullify();
1186 BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1187 TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1190 FunctorType BelongToGenSurface_i::GetFunctorType()
1192 return FT_BelongToGenSurface;
1196 Class : LyingOnGeom_i
1197 Description : Predicate for selection on geometrical support
1199 LyingOnGeom_i::LyingOnGeom_i()
1201 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1202 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1207 LyingOnGeom_i::~LyingOnGeom_i()
1213 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1215 if ( theGeom->_is_nil() )
1217 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1218 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1219 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1220 myLyingOnGeomPtr->SetGeom( aLocShape );
1221 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1224 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1226 myLyingOnGeomPtr->SetGeom( theShape );
1229 void LyingOnGeom_i::SetElementType(ElementType theType){
1230 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1231 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1234 FunctorType LyingOnGeom_i::GetFunctorType()
1236 return SMESH::FT_LyingOnGeom;
1239 void LyingOnGeom_i::SetShapeName( const char* theName )
1242 myShapeName = strdup( theName );
1243 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1244 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1247 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1250 myShapeName = strdup( theName );
1253 myShapeID = strdup( theID );
1257 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1258 myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
1260 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1263 char* LyingOnGeom_i::GetShapeName()
1265 return CORBA::string_dup( myShapeName );
1268 char* LyingOnGeom_i::GetShapeID()
1270 return CORBA::string_dup( myShapeID );
1273 void LyingOnGeom_i::SetTolerance( CORBA::Double theToler )
1275 myLyingOnGeomPtr->SetTolerance( theToler );
1276 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1279 CORBA::Double LyingOnGeom_i::GetTolerance()
1281 return myLyingOnGeomPtr->GetTolerance();
1285 Class : FreeBorders_i
1286 Description : Predicate for free borders
1288 FreeBorders_i::FreeBorders_i()
1290 myPredicatePtr.reset(new Controls::FreeBorders());
1291 myFunctorPtr = myPredicatePtr;
1294 FunctorType FreeBorders_i::GetFunctorType()
1296 return SMESH::FT_FreeBorders;
1301 Description : Predicate for free borders
1303 FreeEdges_i::FreeEdges_i()
1304 : myFreeEdgesPtr( new Controls::FreeEdges() )
1306 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1309 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1311 INFOS("FreeEdges_i::GetBorders");
1312 SMESH::Controls::FreeEdges::TBorders aBorders;
1313 myFreeEdgesPtr->GetBoreders( aBorders );
1315 long i = 0, iEnd = aBorders.size();
1317 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1318 aResult->length(iEnd);
1320 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1321 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1323 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1324 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1326 aBorder.myElemId = aBord.myElemId;
1327 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1328 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1331 INFOS("FreeEdges_i::GetBorders~");
1332 return aResult._retn();
1335 FunctorType FreeEdges_i::GetFunctorType()
1337 return SMESH::FT_FreeEdges;
1342 Description : Predicate for free faces
1344 FreeFaces_i::FreeFaces_i()
1346 myPredicatePtr.reset(new Controls::FreeFaces());
1347 myFunctorPtr = myPredicatePtr;
1350 FunctorType FreeFaces_i::GetFunctorType()
1352 return SMESH::FT_FreeFaces;
1357 Description : Predicate for free nodes
1359 FreeNodes_i::FreeNodes_i()
1361 myPredicatePtr.reset(new Controls::FreeNodes());
1362 myFunctorPtr = myPredicatePtr;
1365 FunctorType FreeNodes_i::GetFunctorType()
1367 return SMESH::FT_FreeNodes;
1371 Class : RangeOfIds_i
1372 Description : Predicate for Range of Ids.
1373 Range may be specified with two ways.
1374 1. Using AddToRange method
1375 2. With SetRangeStr method. Parameter of this method is a string
1376 like as "1,2,3,50-60,63,67,70-"
1379 RangeOfIds_i::RangeOfIds_i()
1381 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1382 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1385 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1387 CORBA::Long iEnd = theIds.length();
1388 for ( CORBA::Long i = 0; i < iEnd; i++ )
1389 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1390 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1393 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1395 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1396 return myRangeOfIdsPtr->SetRangeStr(
1397 TCollection_AsciiString( (Standard_CString)theRange ) );
1400 char* RangeOfIds_i::GetRangeStr()
1402 TCollection_AsciiString aStr;
1403 myRangeOfIdsPtr->GetRangeStr( aStr );
1404 return CORBA::string_dup( aStr.ToCString() );
1407 void RangeOfIds_i::SetElementType( ElementType theType )
1409 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1410 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1413 FunctorType RangeOfIds_i::GetFunctorType()
1415 return SMESH::FT_RangeOfIds;
1419 Class : LinearOrQuadratic_i
1420 Description : Predicate to verify whether a mesh element is linear
1422 LinearOrQuadratic_i::LinearOrQuadratic_i()
1424 myLinearOrQuadraticPtr.reset(new Controls::LinearOrQuadratic());
1425 myFunctorPtr = myPredicatePtr = myLinearOrQuadraticPtr;
1428 void LinearOrQuadratic_i::SetElementType(ElementType theType)
1430 myLinearOrQuadraticPtr->SetType(SMDSAbs_ElementType(theType));
1431 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1434 FunctorType LinearOrQuadratic_i::GetFunctorType()
1436 return SMESH::FT_LinearOrQuadratic;
1440 Class : GroupColor_i
1441 Description : Functor for check color of group to whic mesh element belongs to
1443 GroupColor_i::GroupColor_i()
1445 myGroupColorPtr.reset(new Controls::GroupColor());
1446 myFunctorPtr = myPredicatePtr = myGroupColorPtr;
1449 FunctorType GroupColor_i::GetFunctorType()
1451 return SMESH::FT_GroupColor;
1454 void GroupColor_i::SetColorStr( const char* theColor )
1456 myGroupColorPtr->SetColorStr(
1457 TCollection_AsciiString( (Standard_CString)theColor ) );
1458 TPythonDump()<<this<<".SetColorStr('"<<theColor<<"')";
1461 char* GroupColor_i::GetColorStr()
1463 TCollection_AsciiString aStr;
1464 myGroupColorPtr->GetColorStr( aStr );
1465 return CORBA::string_dup( aStr.ToCString() );
1468 void GroupColor_i::SetElementType(ElementType theType)
1470 myGroupColorPtr->SetType(SMDSAbs_ElementType(theType));
1471 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1475 Class : ElemGeomType_i
1476 Description : Predicate check is element has indicated geometry type
1478 ElemGeomType_i::ElemGeomType_i()
1480 myElemGeomTypePtr.reset(new Controls::ElemGeomType());
1481 myFunctorPtr = myPredicatePtr = myElemGeomTypePtr;
1484 void ElemGeomType_i::SetElementType(ElementType theType)
1486 myElemGeomTypePtr->SetType(SMDSAbs_ElementType(theType));
1487 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1490 void ElemGeomType_i::SetGeometryType(GeometryType theType)
1492 myElemGeomTypePtr->SetGeomType(SMDSAbs_GeometryType(theType));
1493 TPythonDump()<<this<<".SetGeometryType("<<theType<<")";
1496 GeometryType ElemGeomType_i::GetGeometryType() const
1498 return (GeometryType)myElemGeomTypePtr->GetGeomType();;
1501 FunctorType ElemGeomType_i::GetFunctorType()
1503 return SMESH::FT_ElemGeomType;
1507 Class : Comparator_i
1508 Description : Base class for comparators
1510 Comparator_i::Comparator_i():
1511 myNumericalFunctor( NULL )
1514 Comparator_i::~Comparator_i()
1516 if ( myNumericalFunctor )
1517 myNumericalFunctor->Destroy();
1520 void Comparator_i::SetMargin( CORBA::Double theValue )
1522 myComparatorPtr->SetMargin( theValue );
1523 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1526 CORBA::Double Comparator_i::GetMargin()
1528 return myComparatorPtr->GetMargin();
1531 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1533 if ( myNumericalFunctor )
1534 myNumericalFunctor->Destroy();
1536 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1538 if ( myNumericalFunctor )
1540 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1541 myNumericalFunctor->Register();
1542 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1546 Controls::ComparatorPtr Comparator_i::GetComparator()
1548 return myComparatorPtr;
1551 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1553 return myNumericalFunctor;
1559 Description : Comparator "<"
1561 LessThan_i::LessThan_i()
1563 myComparatorPtr.reset( new Controls::LessThan() );
1564 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1567 FunctorType LessThan_i::GetFunctorType()
1569 return SMESH::FT_LessThan;
1575 Description : Comparator ">"
1577 MoreThan_i::MoreThan_i()
1579 myComparatorPtr.reset( new Controls::MoreThan() );
1580 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1583 FunctorType MoreThan_i::GetFunctorType()
1585 return SMESH::FT_MoreThan;
1591 Description : Comparator "="
1593 EqualTo_i::EqualTo_i()
1594 : myEqualToPtr( new Controls::EqualTo() )
1596 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1599 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1601 myEqualToPtr->SetTolerance( theToler );
1602 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1605 CORBA::Double EqualTo_i::GetTolerance()
1607 return myEqualToPtr->GetTolerance();
1610 FunctorType EqualTo_i::GetFunctorType()
1612 return SMESH::FT_EqualTo;
1616 Class : LogicalNOT_i
1617 Description : Logical NOT predicate
1619 LogicalNOT_i::LogicalNOT_i()
1620 : myPredicate( NULL ),
1621 myLogicalNOTPtr( new Controls::LogicalNOT() )
1623 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1626 LogicalNOT_i::~LogicalNOT_i()
1629 myPredicate->Destroy();
1632 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1635 myPredicate->Destroy();
1637 myPredicate = SMESH::GetPredicate(thePredicate);
1640 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1641 myPredicate->Register();
1642 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1646 FunctorType LogicalNOT_i::GetFunctorType()
1648 return SMESH::FT_LogicalNOT;
1651 Predicate_i* LogicalNOT_i::GetPredicate_i()
1658 Class : LogicalBinary_i
1659 Description : Base class for binary logical predicate
1661 LogicalBinary_i::LogicalBinary_i()
1662 : myPredicate1( NULL ),
1663 myPredicate2( NULL )
1666 LogicalBinary_i::~LogicalBinary_i()
1669 myPredicate1->Destroy();
1672 myPredicate2->Destroy();
1675 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1678 myPredicate1->SetMesh( theMesh );
1681 myPredicate2->SetMesh( theMesh );
1684 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1687 myPredicate1->Destroy();
1689 myPredicate1 = SMESH::GetPredicate(thePredicate);
1691 if ( myPredicate1 ){
1692 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1693 myPredicate1->Register();
1694 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1698 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1701 myPredicate2->Destroy();
1703 myPredicate2 = SMESH::GetPredicate(thePredicate);
1705 if ( myPredicate2 ){
1706 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1707 myPredicate2->Register();
1708 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1712 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1714 return myLogicalBinaryPtr;
1717 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1719 return myPredicate1;
1721 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1723 return myPredicate2;
1728 Class : LogicalAND_i
1729 Description : Logical AND
1731 LogicalAND_i::LogicalAND_i()
1733 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1734 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1737 FunctorType LogicalAND_i::GetFunctorType()
1739 return SMESH::FT_LogicalAND;
1745 Description : Logical OR
1747 LogicalOR_i::LogicalOR_i()
1749 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1750 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1753 FunctorType LogicalOR_i::GetFunctorType()
1755 return SMESH::FT_LogicalOR;
1763 FilterManager_i::FilterManager_i()
1764 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1766 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
1767 //PortableServer::ObjectId_var anObjectId =
1768 // SMESH_Gen_i::GetPOA()->activate_object( this );
1772 FilterManager_i::~FilterManager_i()
1774 //TPythonDump()<<this<<".Destroy()";
1778 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1780 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1781 SMESH::MinimumAngle_var anObj = aServant->_this();
1782 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1783 return anObj._retn();
1787 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1789 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1790 SMESH::AspectRatio_var anObj = aServant->_this();
1791 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1792 return anObj._retn();
1796 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1798 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1799 SMESH::AspectRatio3D_var anObj = aServant->_this();
1800 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1801 return anObj._retn();
1805 Warping_ptr FilterManager_i::CreateWarping()
1807 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1808 SMESH::Warping_var anObj = aServant->_this();
1809 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1810 return anObj._retn();
1814 Taper_ptr FilterManager_i::CreateTaper()
1816 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1817 SMESH::Taper_var anObj = aServant->_this();
1818 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1819 return anObj._retn();
1823 Skew_ptr FilterManager_i::CreateSkew()
1825 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1826 SMESH::Skew_var anObj = aServant->_this();
1827 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1828 return anObj._retn();
1832 Area_ptr FilterManager_i::CreateArea()
1834 SMESH::Area_i* aServant = new SMESH::Area_i();
1835 SMESH::Area_var anObj = aServant->_this();
1836 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1837 return anObj._retn();
1841 Volume3D_ptr FilterManager_i::CreateVolume3D()
1843 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
1844 SMESH::Volume3D_var anObj = aServant->_this();
1845 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
1846 return anObj._retn();
1850 MaxElementLength2D_ptr FilterManager_i::CreateMaxElementLength2D()
1852 SMESH::MaxElementLength2D_i* aServant = new SMESH::MaxElementLength2D_i();
1853 SMESH::MaxElementLength2D_var anObj = aServant->_this();
1854 TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength2D()";
1855 return anObj._retn();
1859 MaxElementLength3D_ptr FilterManager_i::CreateMaxElementLength3D()
1861 SMESH::MaxElementLength3D_i* aServant = new SMESH::MaxElementLength3D_i();
1862 SMESH::MaxElementLength3D_var anObj = aServant->_this();
1863 TPythonDump()<<aServant<<" = "<<this<<".CreateMaxElementLength3D()";
1864 return anObj._retn();
1868 Length_ptr FilterManager_i::CreateLength()
1870 SMESH::Length_i* aServant = new SMESH::Length_i();
1871 SMESH::Length_var anObj = aServant->_this();
1872 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1873 return anObj._retn();
1876 Length2D_ptr FilterManager_i::CreateLength2D()
1878 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1879 SMESH::Length2D_var anObj = aServant->_this();
1880 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1881 return anObj._retn();
1884 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1886 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1887 SMESH::MultiConnection_var anObj = aServant->_this();
1888 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1889 return anObj._retn();
1892 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1894 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1895 SMESH::MultiConnection2D_var anObj = aServant->_this();
1896 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
1897 return anObj._retn();
1900 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1902 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1903 SMESH::BelongToGeom_var anObj = aServant->_this();
1904 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
1905 return anObj._retn();
1908 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1910 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1911 SMESH::BelongToPlane_var anObj = aServant->_this();
1912 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
1913 return anObj._retn();
1916 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1918 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1919 SMESH::BelongToCylinder_var anObj = aServant->_this();
1920 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
1921 return anObj._retn();
1924 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
1926 SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
1927 SMESH::BelongToGenSurface_var anObj = aServant->_this();
1928 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
1929 return anObj._retn();
1932 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
1934 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
1935 SMESH::LyingOnGeom_var anObj = aServant->_this();
1936 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
1937 return anObj._retn();
1940 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1942 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1943 SMESH::FreeBorders_var anObj = aServant->_this();
1944 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
1945 return anObj._retn();
1948 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1950 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1951 SMESH::FreeEdges_var anObj = aServant->_this();
1952 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
1953 return anObj._retn();
1956 FreeFaces_ptr FilterManager_i::CreateFreeFaces()
1958 SMESH::FreeFaces_i* aServant = new SMESH::FreeFaces_i();
1959 SMESH::FreeFaces_var anObj = aServant->_this();
1960 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeFaces()";
1961 return anObj._retn();
1964 FreeNodes_ptr FilterManager_i::CreateFreeNodes()
1966 SMESH::FreeNodes_i* aServant = new SMESH::FreeNodes_i();
1967 SMESH::FreeNodes_var anObj = aServant->_this();
1968 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeNodes()";
1969 return anObj._retn();
1972 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1974 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1975 SMESH::RangeOfIds_var anObj = aServant->_this();
1976 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
1977 return anObj._retn();
1980 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
1982 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
1983 SMESH::BadOrientedVolume_var anObj = aServant->_this();
1984 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
1985 return anObj._retn();
1988 LessThan_ptr FilterManager_i::CreateLessThan()
1990 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1991 SMESH::LessThan_var anObj = aServant->_this();
1992 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
1993 return anObj._retn();
1996 MoreThan_ptr FilterManager_i::CreateMoreThan()
1998 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1999 SMESH::MoreThan_var anObj = aServant->_this();
2000 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
2001 return anObj._retn();
2004 EqualTo_ptr FilterManager_i::CreateEqualTo()
2006 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
2007 SMESH::EqualTo_var anObj = aServant->_this();
2008 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
2009 return anObj._retn();
2012 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
2014 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
2015 SMESH::LogicalNOT_var anObj = aServant->_this();
2016 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
2017 return anObj._retn();
2020 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
2022 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
2023 SMESH::LogicalAND_var anObj = aServant->_this();
2024 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
2025 return anObj._retn();
2028 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
2030 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
2031 SMESH::LogicalOR_var anObj = aServant->_this();
2032 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
2033 return anObj._retn();
2036 LinearOrQuadratic_ptr FilterManager_i::CreateLinearOrQuadratic()
2038 SMESH::LinearOrQuadratic_i* aServant = new SMESH::LinearOrQuadratic_i();
2039 SMESH::LinearOrQuadratic_var anObj = aServant->_this();
2040 TPythonDump()<<aServant<<" = "<<this<<".CreateLinearOrQuadratic()";
2041 return anObj._retn();
2044 GroupColor_ptr FilterManager_i::CreateGroupColor()
2046 SMESH::GroupColor_i* aServant = new SMESH::GroupColor_i();
2047 SMESH::GroupColor_var anObj = aServant->_this();
2048 TPythonDump()<<aServant<<" = "<<this<<".CreateGroupColor()";
2049 return anObj._retn();
2052 ElemGeomType_ptr FilterManager_i::CreateElemGeomType()
2054 SMESH::ElemGeomType_i* aServant = new SMESH::ElemGeomType_i();
2055 SMESH::ElemGeomType_var anObj = aServant->_this();
2056 TPythonDump()<<aServant<<" = "<<this<<".CreateElemGeomType()";
2057 return anObj._retn();
2060 Filter_ptr FilterManager_i::CreateFilter()
2062 SMESH::Filter_i* aServant = new SMESH::Filter_i();
2063 SMESH::Filter_var anObj = aServant->_this();
2064 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
2065 return anObj._retn();
2068 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
2070 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
2071 SMESH::FilterLibrary_var anObj = aServant->_this();
2072 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary('"<<aFileName<<"')";
2073 return anObj._retn();
2076 FilterLibrary_ptr FilterManager_i::CreateLibrary()
2078 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
2079 SMESH::FilterLibrary_var anObj = aServant->_this();
2080 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
2081 return anObj._retn();
2084 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
2086 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
2087 return remove( aFileName ) ? false : true;
2090 //=============================================================================
2092 * SMESH_Gen_i::CreateFilterManager
2094 * Create filter manager
2096 //=============================================================================
2098 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
2100 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2101 SMESH::FilterManager_var anObj = aFilter->_this();
2102 return anObj._retn();
2110 //=======================================================================
2111 // name : Filter_i::Filter_i
2112 // Purpose : Constructor
2113 //=======================================================================
2114 Filter_i::Filter_i()
2115 : myPredicate( NULL )
2118 //=======================================================================
2119 // name : Filter_i::~Filter_i
2120 // Purpose : Destructor
2121 //=======================================================================
2122 Filter_i::~Filter_i()
2125 myPredicate->Destroy();
2127 if(!CORBA::is_nil(myMesh))
2130 //TPythonDump()<<this<<".Destroy()";
2133 //=======================================================================
2134 // name : Filter_i::SetPredicate
2135 // Purpose : Set predicate
2136 //=======================================================================
2137 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
2140 myPredicate->Destroy();
2142 myPredicate = SMESH::GetPredicate(thePredicate);
2146 myFilter.SetPredicate( myPredicate->GetPredicate() );
2147 myPredicate->Register();
2148 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
2152 //=======================================================================
2153 // name : Filter_i::GetElementType
2154 // Purpose : Get entity type
2155 //=======================================================================
2156 SMESH::ElementType Filter_i::GetElementType()
2158 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
2161 //=======================================================================
2162 // name : Filter_i::SetMesh
2163 // Purpose : Set mesh
2164 //=======================================================================
2167 SetMesh( SMESH_Mesh_ptr theMesh )
2169 if(!CORBA::is_nil(theMesh))
2170 theMesh->Register();
2172 if(!CORBA::is_nil(myMesh))
2175 myMesh = SMESH_Mesh::_duplicate( theMesh );
2176 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
2183 return GetElementsId(myMesh);
2186 //=======================================================================
2187 // name : Filter_i::GetElementsId
2188 // Purpose : Get ids of entities
2189 //=======================================================================
2192 GetElementsId( Predicate_i* thePredicate,
2193 const SMDS_Mesh* theMesh,
2194 Controls::Filter::TIdSequence& theSequence )
2197 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
2202 GetElementsId( Predicate_i* thePredicate,
2203 SMESH_Mesh_ptr theMesh,
2204 Controls::Filter::TIdSequence& theSequence )
2207 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
2208 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
2213 GetElementsId( SMESH_Mesh_ptr theMesh )
2215 SMESH::long_array_var anArray = new SMESH::long_array;
2216 if(!CORBA::is_nil(theMesh) && myPredicate){
2217 Controls::Filter::TIdSequence aSequence;
2218 GetElementsId(myPredicate,theMesh,aSequence);
2219 long i = 0, iEnd = aSequence.size();
2220 anArray->length( iEnd );
2221 for ( ; i < iEnd; i++ )
2222 anArray[ i ] = aSequence[i];
2224 return anArray._retn();
2227 template<class TElement, class TIterator, class TPredicate>
2228 static void collectMeshInfo(const TIterator& theItr,
2229 TPredicate& thePred,
2230 SMESH::long_array& theRes)
2234 while (theItr->more()) {
2235 const SMDS_MeshElement* anElem = theItr->next();
2236 if ( thePred->IsSatisfy( anElem->GetID() ) )
2237 theRes[ anElem->GetEntityType() ]++;
2241 //=============================================================================
2243 * \brief Returns statistic of mesh elements
2245 //=============================================================================
2246 SMESH::long_array* ::Filter_i::GetMeshInfo()
2248 SMESH::long_array_var aRes = new SMESH::long_array();
2249 aRes->length(SMESH::Entity_Last);
2250 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
2253 if(!CORBA::is_nil(myMesh) && myPredicate) {
2254 const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
2255 SMDS_ElemIteratorPtr it;
2256 switch( GetElementType() )
2259 collectMeshInfo<const SMDS_MeshNode*>(aMesh->nodesIterator(),myPredicate,aRes);
2262 collectMeshInfo<const SMDS_MeshElement*>(aMesh->edgesIterator(),myPredicate,aRes);
2265 collectMeshInfo<const SMDS_MeshElement*>(aMesh->facesIterator(),myPredicate,aRes);
2267 case SMDSAbs_Volume:
2268 collectMeshInfo<const SMDS_MeshElement*>(aMesh->volumesIterator(),myPredicate,aRes);
2272 collectMeshInfo<const SMDS_MeshElement*>(aMesh->elementsIterator(),myPredicate,aRes);
2278 return aRes._retn();
2281 //================================================================================
2283 * \brief Return GetElementType() within an array
2284 * Implement SMESH_IDSource interface
2286 //================================================================================
2288 SMESH::array_of_ElementType* Filter_i::GetTypes()
2290 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
2292 types[0] = GetElementType();
2293 return types._retn();
2296 //=======================================================================
2297 //function : GetMesh
2298 //purpose : Returns mesh
2299 //=======================================================================
2301 SMESH::SMESH_Mesh_ptr Filter_i::GetMesh()
2303 return SMESH_Mesh::_duplicate( myMesh );
2306 //=======================================================================
2307 // name : getCriteria
2308 // Purpose : Retrieve criterions from predicate
2309 //=======================================================================
2310 static inline bool getCriteria( Predicate_i* thePred,
2311 SMESH::Filter::Criteria_out theCriteria )
2313 int aFType = thePred->GetFunctorType();
2317 case FT_FreeBorders:
2320 case FT_LinearOrQuadratic:
2323 CORBA::ULong i = theCriteria->length();
2324 theCriteria->length( i + 1 );
2326 theCriteria[ i ] = createCriterion();
2328 theCriteria[ i ].Type = aFType;
2329 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
2332 case FT_BelongToGeom:
2334 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
2336 CORBA::ULong i = theCriteria->length();
2337 theCriteria->length( i + 1 );
2339 theCriteria[ i ] = createCriterion();
2341 theCriteria[ i ].Type = FT_BelongToGeom;
2342 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2343 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2344 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2345 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2349 case FT_BelongToPlane:
2350 case FT_BelongToCylinder:
2351 case FT_BelongToGenSurface:
2353 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
2355 CORBA::ULong i = theCriteria->length();
2356 theCriteria->length( i + 1 );
2358 theCriteria[ i ] = createCriterion();
2360 theCriteria[ i ].Type = aFType;
2361 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2362 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2363 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2364 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2368 case FT_LyingOnGeom:
2370 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
2372 CORBA::ULong i = theCriteria->length();
2373 theCriteria->length( i + 1 );
2375 theCriteria[ i ] = createCriterion();
2377 theCriteria[ i ].Type = FT_LyingOnGeom;
2378 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
2379 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
2380 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2381 theCriteria[ i ].Tolerance = aPred->GetTolerance();
2387 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
2389 CORBA::ULong i = theCriteria->length();
2390 theCriteria->length( i + 1 );
2392 theCriteria[ i ] = createCriterion();
2394 theCriteria[ i ].Type = FT_RangeOfIds;
2395 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
2396 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2400 case FT_BadOrientedVolume:
2402 BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
2404 CORBA::ULong i = theCriteria->length();
2405 theCriteria->length( i + 1 );
2407 theCriteria[ i ] = createCriterion();
2409 theCriteria[ i ].Type = FT_BadOrientedVolume;
2410 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2418 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
2420 CORBA::ULong i = theCriteria->length();
2421 theCriteria->length( i + 1 );
2423 theCriteria[ i ] = createCriterion();
2425 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
2426 theCriteria[ i ].Compare = aFType;
2427 theCriteria[ i ].Threshold = aCompar->GetMargin();
2428 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
2430 if ( aFType == FT_EqualTo )
2432 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
2433 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
2440 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
2441 getCriteria( aPred, theCriteria );
2442 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2449 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2450 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2451 if ( !getCriteria( aPred1, theCriteria ) )
2453 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2454 return getCriteria( aPred2, theCriteria );
2458 CORBA::ULong i = theCriteria->length();
2459 theCriteria->length( i + 1 );
2461 theCriteria[ i ] = createCriterion();
2463 GroupColor_i* aPred = dynamic_cast<GroupColor_i*>( thePred );
2464 theCriteria[ i ].Type = aFType;
2465 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2466 theCriteria[ i ].ThresholdStr = aPred->GetColorStr();
2470 case FT_ElemGeomType:
2472 CORBA::ULong i = theCriteria->length();
2473 theCriteria->length( i + 1 );
2475 theCriteria[ i ] = createCriterion();
2477 ElemGeomType_i* aPred = dynamic_cast<ElemGeomType_i*>( thePred );
2478 theCriteria[ i ].Type = aFType;
2479 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
2480 theCriteria[ i ].Threshold = (double)aPred->GetGeometryType();
2491 //=======================================================================
2492 // name : Filter_i::GetCriteria
2493 // Purpose : Retrieve criterions from predicate
2494 //=======================================================================
2495 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2497 theCriteria = new SMESH::Filter::Criteria;
2498 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2501 //=======================================================================
2502 // name : Filter_i::SetCriteria
2503 // Purpose : Create new predicate and set criterions in it
2504 //=======================================================================
2505 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2507 if ( myPredicate != 0 )
2508 myPredicate->Destroy();
2510 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2511 FilterManager_ptr aFilterMgr = aFilter->_this();
2513 // CREATE two lists ( PREDICATES and LOG OP )
2516 TPythonDump()<<"aCriteria = []";
2517 std::list<SMESH::Predicate_ptr> aPredicates;
2518 std::list<int> aBinaries;
2519 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2521 int aCriterion = theCriteria[ i ].Type;
2522 int aCompare = theCriteria[ i ].Compare;
2523 double aThreshold = theCriteria[ i ].Threshold;
2524 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2525 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2526 int aUnary = theCriteria[ i ].UnaryOp;
2527 int aBinary = theCriteria[ i ].BinaryOp;
2528 double aTolerance = theCriteria[ i ].Tolerance;
2529 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
2530 long aPrecision = theCriteria[ i ].Precision;
2534 pd << "aCriterion = SMESH.Filter.Criterion(" << aCriterion << "," << aCompare
2535 << "," << aThreshold << ",'" << aThresholdStr;
2536 if (aThresholdID && strlen(aThresholdID))
2537 //pd << "',salome.ObjectToID(" << aThresholdID
2538 pd << "','" << aThresholdID
2539 << "'," << aUnary << "," << aBinary << "," << aTolerance
2540 << "," << aTypeOfElem << "," << aPrecision << ")";
2542 pd << "',''," << aUnary << "," << aBinary << "," << aTolerance
2543 << "," << aTypeOfElem << "," << aPrecision << ")";
2546 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2547 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2549 switch ( aCriterion )
2553 case SMESH::FT_MultiConnection:
2554 aFunctor = aFilterMgr->CreateMultiConnection();
2556 case SMESH::FT_MultiConnection2D:
2557 aFunctor = aFilterMgr->CreateMultiConnection2D();
2559 case SMESH::FT_Length:
2560 aFunctor = aFilterMgr->CreateLength();
2562 case SMESH::FT_Length2D:
2563 aFunctor = aFilterMgr->CreateLength2D();
2565 case SMESH::FT_AspectRatio:
2566 aFunctor = aFilterMgr->CreateAspectRatio();
2568 case SMESH::FT_AspectRatio3D:
2569 aFunctor = aFilterMgr->CreateAspectRatio3D();
2571 case SMESH::FT_Warping:
2572 aFunctor = aFilterMgr->CreateWarping();
2574 case SMESH::FT_MinimumAngle:
2575 aFunctor = aFilterMgr->CreateMinimumAngle();
2577 case SMESH::FT_Taper:
2578 aFunctor = aFilterMgr->CreateTaper();
2580 case SMESH::FT_Skew:
2581 aFunctor = aFilterMgr->CreateSkew();
2583 case SMESH::FT_Area:
2584 aFunctor = aFilterMgr->CreateArea();
2586 case SMESH::FT_Volume3D:
2587 aFunctor = aFilterMgr->CreateVolume3D();
2589 case SMESH::FT_MaxElementLength2D:
2590 aFunctor = aFilterMgr->CreateMaxElementLength2D();
2592 case SMESH::FT_MaxElementLength3D:
2593 aFunctor = aFilterMgr->CreateMaxElementLength3D();
2598 case SMESH::FT_FreeBorders:
2599 aPredicate = aFilterMgr->CreateFreeBorders();
2601 case SMESH::FT_FreeEdges:
2602 aPredicate = aFilterMgr->CreateFreeEdges();
2604 case SMESH::FT_FreeFaces:
2605 aPredicate = aFilterMgr->CreateFreeFaces();
2607 case SMESH::FT_FreeNodes:
2608 aPredicate = aFilterMgr->CreateFreeNodes();
2610 case SMESH::FT_BelongToGeom:
2612 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2613 tmpPred->SetElementType( aTypeOfElem );
2614 tmpPred->SetShape( aThresholdID, aThresholdStr );
2615 tmpPred->SetTolerance( aTolerance );
2616 aPredicate = tmpPred;
2619 case SMESH::FT_BelongToPlane:
2620 case SMESH::FT_BelongToCylinder:
2621 case SMESH::FT_BelongToGenSurface:
2623 SMESH::BelongToSurface_ptr tmpPred;
2624 switch ( aCriterion ) {
2625 case SMESH::FT_BelongToPlane:
2626 tmpPred = aFilterMgr->CreateBelongToPlane(); break;
2627 case SMESH::FT_BelongToCylinder:
2628 tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
2630 tmpPred = aFilterMgr->CreateBelongToGenSurface();
2632 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2633 tmpPred->SetTolerance( aTolerance );
2634 aPredicate = tmpPred;
2637 case SMESH::FT_LyingOnGeom:
2639 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2640 tmpPred->SetElementType( aTypeOfElem );
2641 tmpPred->SetShape( aThresholdID, aThresholdStr );
2642 tmpPred->SetTolerance( aTolerance );
2643 aPredicate = tmpPred;
2646 case SMESH::FT_RangeOfIds:
2648 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2649 tmpPred->SetRangeStr( aThresholdStr );
2650 tmpPred->SetElementType( aTypeOfElem );
2651 aPredicate = tmpPred;
2654 case SMESH::FT_BadOrientedVolume:
2656 aPredicate = aFilterMgr->CreateBadOrientedVolume();
2659 case SMESH::FT_LinearOrQuadratic:
2661 SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic();
2662 tmpPred->SetElementType( aTypeOfElem );
2663 aPredicate = tmpPred;
2666 case SMESH::FT_GroupColor:
2668 SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor();
2669 tmpPred->SetElementType( aTypeOfElem );
2670 tmpPred->SetColorStr( aThresholdStr );
2671 aPredicate = tmpPred;
2674 case SMESH::FT_ElemGeomType:
2676 SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType();
2677 tmpPred->SetElementType( aTypeOfElem );
2678 tmpPred->SetGeometryType( (GeometryType)(int)(aThreshold + 0.5) );
2679 aPredicate = tmpPred;
2688 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
2690 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
2692 if ( aCompare == SMESH::FT_LessThan )
2693 aComparator = aFilterMgr->CreateLessThan();
2694 else if ( aCompare == SMESH::FT_MoreThan )
2695 aComparator = aFilterMgr->CreateMoreThan();
2696 else if ( aCompare == SMESH::FT_EqualTo )
2697 aComparator = aFilterMgr->CreateEqualTo();
2701 aComparator->SetNumFunctor( aFunctor );
2702 aComparator->SetMargin( aThreshold );
2704 if ( aCompare == FT_EqualTo )
2706 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
2707 anEqualTo->SetTolerance( aTolerance );
2710 aPredicate = aComparator;
2712 aFunctor->SetPrecision( aPrecision );
2716 if ( aUnary == FT_LogicalNOT )
2718 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
2719 aNotPred->SetPredicate( aPredicate );
2720 aPredicate = aNotPred;
2724 aPredicates.push_back( aPredicate );
2725 aBinaries.push_back( aBinary );
2726 TPythonDump()<<"aCriteria.append(aCriterion)";
2729 TPythonDump()<<this<<".SetCriteria(aCriteria)";
2731 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
2733 // combine all "AND" operations
2735 std::list<SMESH::Predicate_ptr> aResList;
2737 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
2738 std::list<int>::iterator aBinaryIter;
2740 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
2741 int aPrevBinary = SMESH::FT_Undefined;
2743 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
2744 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
2745 ++aPredIter, ++aBinaryIter )
2747 int aCurrBinary = *aBinaryIter;
2749 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
2751 if ( aPrevBinary == SMESH::FT_LogicalAND )
2754 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2755 aBinaryPred->SetPredicate1( aPrevPredicate );
2756 aBinaryPred->SetPredicate2( *aPredIter );
2757 aCurrPred = aBinaryPred;
2760 aCurrPred = *aPredIter;
2762 if ( aCurrBinary != SMESH::FT_LogicalAND )
2763 aResList.push_back( aCurrPred );
2765 aPrevPredicate = aCurrPred;
2766 aPrevBinary = aCurrBinary;
2769 // combine all "OR" operations
2771 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2773 if ( aResList.size() == 1 )
2774 aResPredicate = *aResList.begin();
2775 else if ( aResList.size() > 1 )
2777 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2778 aResPredicate = *anIter;
2780 for ( ; anIter != aResList.end(); ++anIter )
2782 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2783 aBinaryPred->SetPredicate1( aResPredicate );
2784 aBinaryPred->SetPredicate2( *anIter );
2785 aResPredicate = aBinaryPred;
2789 SetPredicate( aResPredicate );
2791 return !aResPredicate->_is_nil();
2794 //=======================================================================
2795 // name : Filter_i::GetPredicate_i
2796 // Purpose : Get implementation of predicate
2797 //=======================================================================
2798 Predicate_i* Filter_i::GetPredicate_i()
2803 //=======================================================================
2804 // name : Filter_i::GetPredicate
2805 // Purpose : Get predicate
2806 //=======================================================================
2807 Predicate_ptr Filter_i::GetPredicate()
2809 if ( myPredicate == 0 )
2810 return SMESH::Predicate::_nil();
2813 SMESH::Predicate_var anObj = myPredicate->_this();
2814 return anObj._retn();
2822 #define ATTR_TYPE "type"
2823 #define ATTR_COMPARE "compare"
2824 #define ATTR_THRESHOLD "threshold"
2825 #define ATTR_UNARY "unary"
2826 #define ATTR_BINARY "binary"
2827 #define ATTR_THRESHOLD_STR "threshold_str"
2828 #define ATTR_TOLERANCE "tolerance"
2829 #define ATTR_ELEMENT_TYPE "ElementType"
2831 //=======================================================================
2833 // Purpose : Convert bool to LDOMString
2834 //=======================================================================
2835 static inline LDOMString toString( CORBA::Boolean val )
2837 return val ? "logical not" : "";
2840 //=======================================================================
2842 // Purpose : Convert LDOMString to bool
2843 //=======================================================================
2844 static inline bool toBool( const LDOMString& theStr )
2846 return theStr.equals( "logical not" );
2849 //=======================================================================
2851 // Purpose : Convert double to LDOMString
2852 //=======================================================================
2853 static inline LDOMString toString( CORBA::Double val )
2856 sprintf( a, "%e", val );
2857 return LDOMString( a );
2860 //=======================================================================
2862 // Purpose : Convert LDOMString to double
2863 //=======================================================================
2864 static inline double toDouble( const LDOMString& theStr )
2866 return atof( theStr.GetString() );
2869 //=======================================================================
2871 // Purpose : Convert functor type to LDOMString
2872 //=======================================================================
2873 static inline LDOMString toString( CORBA::Long theType )
2877 case FT_AspectRatio : return "Aspect ratio";
2878 case FT_Warping : return "Warping";
2879 case FT_MinimumAngle : return "Minimum angle";
2880 case FT_Taper : return "Taper";
2881 case FT_Skew : return "Skew";
2882 case FT_Area : return "Area";
2883 case FT_Volume3D : return "Volume3D";
2884 case FT_MaxElementLength2D: return "Max element length 2D";
2885 case FT_MaxElementLength3D: return "Max element length 3D";
2886 case FT_BelongToGeom : return "Belong to Geom";
2887 case FT_BelongToPlane : return "Belong to Plane";
2888 case FT_BelongToCylinder: return "Belong to Cylinder";
2889 case FT_BelongToGenSurface: return "Belong to Generic Surface";
2890 case FT_LyingOnGeom : return "Lying on Geom";
2891 case FT_BadOrientedVolume: return "Bad Oriented Volume";
2892 case FT_RangeOfIds : return "Range of IDs";
2893 case FT_FreeBorders : return "Free borders";
2894 case FT_FreeEdges : return "Free edges";
2895 case FT_FreeFaces : return "Free faces";
2896 case FT_FreeNodes : return "Free nodes";
2897 case FT_MultiConnection : return "Borders at multi-connections";
2898 case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2899 case FT_Length : return "Length";
2900 case FT_Length2D : return "Length 2D";
2901 case FT_LessThan : return "Less than";
2902 case FT_MoreThan : return "More than";
2903 case FT_EqualTo : return "Equal to";
2904 case FT_LogicalNOT : return "Not";
2905 case FT_LogicalAND : return "And";
2906 case FT_LogicalOR : return "Or";
2907 case FT_GroupColor : return "Color of Group";
2908 case FT_LinearOrQuadratic : return "Linear or Quadratic";
2909 case FT_ElemGeomType : return "Element geomtry type";
2910 case FT_Undefined : return "";
2911 default : return "";
2915 //=======================================================================
2916 // name : toFunctorType
2917 // Purpose : Convert LDOMString to functor type
2918 //=======================================================================
2919 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
2921 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
2922 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
2923 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
2924 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
2925 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
2926 else if ( theStr.equals( "Area" ) ) return FT_Area;
2927 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
2928 else if ( theStr.equals( "Max element length 2D" ) ) return FT_MaxElementLength2D;
2929 else if ( theStr.equals( "Max element length 3D" ) ) return FT_MaxElementLength3D;
2930 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
2931 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
2932 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
2933 else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface;
2934 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
2935 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
2936 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
2937 else if ( theStr.equals( "Free faces" ) ) return FT_FreeFaces;
2938 else if ( theStr.equals( "Free nodes" ) ) return FT_FreeNodes;
2939 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
2940 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
2941 else if ( theStr.equals( "Length" ) ) return FT_Length;
2942 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
2943 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
2944 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
2945 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
2946 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
2947 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
2948 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
2949 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
2950 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
2951 else if ( theStr.equals( "Color of Group" ) ) return FT_GroupColor;
2952 else if ( theStr.equals( "Linear or Quadratic" ) ) return FT_LinearOrQuadratic;
2953 else if ( theStr.equals( "Element geomtry type" ) ) return FT_ElemGeomType;
2954 else if ( theStr.equals( "" ) ) return FT_Undefined;
2955 else return FT_Undefined;
2958 //=======================================================================
2959 // name : toFunctorType
2960 // Purpose : Convert LDOMString to value of ElementType enumeration
2961 //=======================================================================
2962 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
2964 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
2965 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
2966 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
2967 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
2968 else return SMESH::ALL;
2971 //=======================================================================
2973 // Purpose : Convert ElementType to string
2974 //=======================================================================
2975 static inline LDOMString toString( const SMESH::ElementType theType )
2979 case SMESH::NODE : return "NODE";
2980 case SMESH::EDGE : return "EDGE";
2981 case SMESH::FACE : return "FACE";
2982 case SMESH::VOLUME : return "VOLUME";
2983 case SMESH::ALL : return "ALL";
2984 default : return "";
2988 //=======================================================================
2989 // name : findFilter
2990 // Purpose : Find filter in document
2991 //=======================================================================
2992 static LDOM_Element findFilter( const char* theFilterName,
2993 const LDOM_Document& theDoc,
2994 LDOM_Node* theParent = 0 )
2996 LDOM_Element aRootElement = theDoc.getDocumentElement();
2997 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
2998 return LDOM_Element();
3000 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
3001 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
3003 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
3004 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3006 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
3007 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
3008 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
3010 if ( theParent != 0 )
3011 *theParent = aTypeNode;
3012 return (LDOM_Element&)aFilter;
3016 return LDOM_Element();
3019 //=======================================================================
3020 // name : getSectionName
3021 // Purpose : Get name of section of filters
3022 //=======================================================================
3023 static const char* getSectionName( const ElementType theType )
3027 case SMESH::NODE : return "Filters for nodes";
3028 case SMESH::EDGE : return "Filters for edges";
3029 case SMESH::FACE : return "Filters for faces";
3030 case SMESH::VOLUME : return "Filters for volumes";
3031 case SMESH::ALL : return "Filters for elements";
3032 default : return "";
3036 //=======================================================================
3037 // name : getSection
3038 // Purpose : Create section for filters corresponding to the entity type
3039 //=======================================================================
3040 static LDOM_Node getSection( const ElementType theType,
3041 LDOM_Document& theDoc,
3042 const bool toCreate = false )
3044 LDOM_Element aRootElement = theDoc.getDocumentElement();
3045 if ( aRootElement.isNull() )
3049 bool anExist = false;
3050 const char* aSectionName = getSectionName( theType );
3051 if ( strcmp( aSectionName, "" ) == 0 )
3054 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
3056 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
3058 aNode = aSections.item( i );
3059 LDOM_Element& anItem = ( LDOM_Element& )aNode;
3060 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
3067 // Create new section if necessary
3072 LDOM_Element aNewItem = theDoc.createElement( "section" );
3073 aNewItem.setAttribute( "name", aSectionName );
3074 aRootElement.appendChild( aNewItem );
3084 //=======================================================================
3085 // name : createFilterItem
3086 // Purpose : Create filter item or LDOM document
3087 //=======================================================================
3088 static LDOM_Element createFilterItem( const char* theName,
3089 SMESH::Filter_ptr theFilter,
3090 LDOM_Document& theDoc )
3092 // create new filter in document
3093 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
3094 aFilterItem.setAttribute( "name", theName );
3096 // save filter criterions
3097 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3099 if ( !theFilter->GetCriteria( aCriteria ) )
3100 return LDOM_Element();
3102 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
3104 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
3106 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
3107 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
3108 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
3109 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
3110 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
3112 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
3113 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
3114 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
3115 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
3117 aFilterItem.appendChild( aCriterionItem );
3123 //=======================================================================
3124 // name : FilterLibrary_i::FilterLibrary_i
3125 // Purpose : Constructor
3126 //=======================================================================
3127 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
3129 myFileName = strdup( theFileName );
3130 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
3131 myFilterMgr = aFilterMgr->_this();
3135 // Try to use existing library file
3136 bool anExists = false;
3137 if ( !aParser.parse( myFileName ) )
3139 myDoc = aParser.getDocument();
3142 // Create a new XML document if it doesn't exist
3144 myDoc = LDOM_Document::createDocument( LDOMString() );
3146 LDOM_Element aRootElement = myDoc.getDocumentElement();
3147 if ( aRootElement.isNull() )
3149 // If the existing document is empty --> try to create a new one
3151 myDoc = LDOM_Document::createDocument( LDOMString() );
3155 //=======================================================================
3156 // name : FilterLibrary_i::FilterLibrary_i
3157 // Purpose : Constructor
3158 //=======================================================================
3159 FilterLibrary_i::FilterLibrary_i()
3162 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
3163 myFilterMgr = aFilter->_this();
3165 myDoc = LDOM_Document::createDocument( LDOMString() );
3168 FilterLibrary_i::~FilterLibrary_i()
3171 //TPythonDump()<<this<<".Destroy()";
3174 //=======================================================================
3175 // name : FilterLibrary_i::Copy
3176 // Purpose : Create filter and initialize it with values from library
3177 //=======================================================================
3178 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
3180 Filter_ptr aRes = Filter::_nil();
3181 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
3183 if ( aFilter.isNull() )
3186 std::list<SMESH::Filter::Criterion> aCriteria;
3188 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
3189 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
3191 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
3193 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
3194 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
3195 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
3196 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
3197 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
3199 SMESH::Filter::Criterion aCriterion = createCriterion();
3201 aCriterion.Type = toFunctorType( aTypeStr );
3202 aCriterion.Compare = toFunctorType( aCompareStr );
3203 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
3204 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
3206 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
3208 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
3210 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3211 ? val : atof( str.GetString() );
3213 str = aCrit->getAttribute( ATTR_TOLERANCE );
3214 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
3215 ? val : atof( str.GetString() );
3217 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
3218 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
3221 sprintf( a, "%d", val );
3222 aCriterion.ThresholdStr = strdup( a );
3225 aCriterion.ThresholdStr = str.GetString();
3227 aCriteria.push_back( aCriterion );
3230 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
3231 aCriteriaVar->length( aCriteria.size() );
3234 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
3236 for( ; anIter != aCriteria.end(); ++anIter )
3237 aCriteriaVar[ i++ ] = *anIter;
3239 aRes = myFilterMgr->CreateFilter();
3240 aRes->SetCriteria( aCriteriaVar.inout() );
3242 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
3247 //=======================================================================
3248 // name : FilterLibrary_i::SetFileName
3249 // Purpose : Set file name for library
3250 //=======================================================================
3251 void FilterLibrary_i::SetFileName( const char* theFileName )
3254 myFileName = strdup( theFileName );
3255 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
3258 //=======================================================================
3259 // name : FilterLibrary_i::GetFileName
3260 // Purpose : Get file name of library
3261 //=======================================================================
3262 char* FilterLibrary_i::GetFileName()
3264 return CORBA::string_dup( myFileName );
3267 //=======================================================================
3268 // name : FilterLibrary_i::Add
3269 // Purpose : Add new filter to library
3270 //=======================================================================
3271 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
3273 // if filter already in library or entry filter is null do nothing
3274 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3275 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
3278 // get section corresponding to the filter type
3279 ElementType anEntType = theFilter->GetElementType();
3281 LDOM_Node aSection = getSection( anEntType, myDoc, true );
3282 if ( aSection.isNull() )
3285 // create filter item
3286 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
3287 if ( aFilterItem.isNull() )
3291 aSection.appendChild( aFilterItem );
3292 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3293 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
3298 //=======================================================================
3299 // name : FilterLibrary_i::Add
3300 // Purpose : Add new filter to library
3301 //=======================================================================
3302 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
3304 // if filter already in library or entry filter is null do nothing
3305 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
3306 if ( !aFilterNode.isNull() )
3309 LDOM_Node aSection = getSection( theType, myDoc, true );
3310 if ( aSection.isNull() )
3313 // create filter item
3314 Filter_var aFilter = myFilterMgr->CreateFilter();
3316 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
3317 if ( aFilterItem.isNull() )
3321 aSection.appendChild( aFilterItem );
3322 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
3327 //=======================================================================
3328 // name : FilterLibrary_i::Delete
3329 // Purpose : Delete filter from library
3330 //=======================================================================
3331 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
3333 LDOM_Node aParentNode;
3334 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
3335 if ( aFilterNode.isNull() || aParentNode.isNull() )
3338 aParentNode.removeChild( aFilterNode );
3339 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
3343 //=======================================================================
3344 // name : FilterLibrary_i::Replace
3345 // Purpose : Replace existing filter with entry filter.
3346 // IMPORTANT : If filter does not exist it is not created
3347 //=======================================================================
3348 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
3349 const char* theNewName,
3350 Filter_ptr theFilter )
3352 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
3353 if ( aFilterItem.isNull() || theFilter->_is_nil() )
3356 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
3357 if ( aNewItem.isNull() )
3361 aFilterItem.ReplaceElement( aNewItem );
3362 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
3363 TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
3368 //=======================================================================
3369 // name : FilterLibrary_i::Save
3370 // Purpose : Save library on disk
3371 //=======================================================================
3372 CORBA::Boolean FilterLibrary_i::Save()
3374 if ( myFileName == 0 || strlen( myFileName ) == 0 )
3377 FILE* aOutFile = fopen( myFileName, "wt" );
3381 LDOM_XmlWriter aWriter( aOutFile );
3382 aWriter.SetIndentation( 2 );
3386 TPythonDump()<<this<<".Save()";
3390 //=======================================================================
3391 // name : FilterLibrary_i::SaveAs
3392 // Purpose : Save library on disk
3393 //=======================================================================
3394 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
3396 myFileName = strdup ( aFileName );
3397 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
3401 //=======================================================================
3402 // name : FilterLibrary_i::IsPresent
3403 // Purpose : Verify whether filter is in library
3404 //=======================================================================
3405 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
3407 return !findFilter( theFilterName, myDoc ).isNull();
3410 //=======================================================================
3411 // name : FilterLibrary_i::NbFilters
3412 // Purpose : Return amount of filters in library
3413 //=======================================================================
3414 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
3416 string_array_var aNames = GetNames( theType );
3417 return aNames->length();
3420 //=======================================================================
3421 // name : FilterLibrary_i::GetNames
3422 // Purpose : Get names of filters from library
3423 //=======================================================================
3424 string_array* FilterLibrary_i::GetNames( ElementType theType )
3426 string_array_var anArray = new string_array;
3427 TColStd_SequenceOfHAsciiString aSeq;
3429 LDOM_Node aSection = getSection( theType, myDoc, false );
3431 if ( !aSection.isNull() )
3433 for ( LDOM_Node aFilter = aSection.getFirstChild();
3434 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
3436 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
3437 aSeq.Append( new TCollection_HAsciiString(
3438 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
3442 anArray->length( aSeq.Length() );
3443 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
3444 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
3446 return anArray._retn();
3449 //=======================================================================
3450 // name : FilterLibrary_i::GetAllNames
3451 // Purpose : Get names of filters from library
3452 //=======================================================================
3453 string_array* FilterLibrary_i::GetAllNames()
3455 string_array_var aResArray = new string_array;
3456 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
3458 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
3460 int aPrevLength = aResArray->length();
3461 aResArray->length( aPrevLength + aNames->length() );
3462 for ( int i = 0, n = aNames->length(); i < n; i++ )
3463 aResArray[ aPrevLength + i ] = aNames[ i ];
3466 return aResArray._retn();