1 // Copyright (C) 2007-2008 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
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_Filter_i.cxx
24 // Author : Alexey Petrov, OCC
27 #include "SMESH_Filter_i.hxx"
29 #include "SMESH_Gen_i.hxx"
30 #include "SMESH_PythonDump.hxx"
32 #include "SMDS_Mesh.hxx"
33 #include "SMDS_MeshNode.hxx"
34 #include "SMDS_MeshElement.hxx"
36 #include "SMESHDS_Mesh.hxx"
38 #include <BRep_Tool.hxx>
39 #include <Geom_CylindricalSurface.hxx>
40 #include <Geom_Plane.hxx>
41 #include <LDOMParser.hxx>
42 #include <LDOMString.hxx>
43 #include <LDOM_Document.hxx>
44 #include <LDOM_Element.hxx>
45 #include <LDOM_Node.hxx>
46 #include <LDOM_XmlWriter.hxx>
47 #include <Precision.hxx>
48 #include <TColStd_ListIteratorOfListOfInteger.hxx>
49 #include <TColStd_ListIteratorOfListOfReal.hxx>
50 #include <TColStd_ListOfInteger.hxx>
51 #include <TColStd_ListOfReal.hxx>
52 #include <TColStd_SequenceOfHAsciiString.hxx>
53 #include <TCollection_HAsciiString.hxx>
55 #include <TopExp_Explorer.hxx>
57 #include <TopoDS_Face.hxx>
58 #include <TopoDS_Shape.hxx>
60 using namespace SMESH;
61 using namespace SMESH::Controls;
67 GetPredicate( Predicate_ptr thePredicate )
69 return DownCast<Predicate_i*>(thePredicate);
76 Description : Predicate for verifying whether entiy belong to
77 specified geometrical support
80 Controls::BelongToGeom::BelongToGeom()
85 void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
87 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
90 void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
95 static bool IsContains( const SMESHDS_Mesh* theMeshDS,
96 const TopoDS_Shape& theShape,
97 const SMDS_MeshElement* theElem,
98 TopAbs_ShapeEnum theFindShapeEnum,
99 TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE )
101 TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
103 while( anExp.More() )
105 const TopoDS_Shape& aShape = anExp.Current();
106 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
107 if( aSubMesh->Contains( theElem ) )
115 bool Controls::BelongToGeom::IsSatisfy( long theId )
117 if ( myMeshDS == 0 || myShape.IsNull() )
120 if( myType == SMDSAbs_Node )
122 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
124 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
125 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
126 switch( aTypeOfPosition )
128 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
129 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
130 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
131 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
137 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
139 if( myType == SMDSAbs_All )
141 return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
142 IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
143 IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
144 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
146 else if( myType == anElem->GetType() )
150 case SMDSAbs_Edge : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
151 case SMDSAbs_Face : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
152 case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
153 IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
162 void Controls::BelongToGeom::SetType( SMDSAbs_ElementType theType )
167 SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
172 TopoDS_Shape Controls::BelongToGeom::GetShape()
178 Controls::BelongToGeom::
186 Description : Predicate for verifying whether entiy lying or partially lying on
187 specified geometrical support
190 Controls::LyingOnGeom::LyingOnGeom()
195 void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
197 myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
200 void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
205 bool Controls::LyingOnGeom::IsSatisfy( long theId )
207 if ( myMeshDS == 0 || myShape.IsNull() )
210 if( myType == SMDSAbs_Node )
212 if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
214 const SMDS_PositionPtr& aPosition = aNode->GetPosition();
215 SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
216 switch( aTypeOfPosition )
218 case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
219 case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
220 case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
221 case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
227 if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
229 if( myType == SMDSAbs_All )
231 return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
232 Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
233 Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
234 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
236 else if( myType == anElem->GetType() )
240 case SMDSAbs_Edge : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
241 case SMDSAbs_Face : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
242 case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
243 Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
252 void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
257 SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
262 TopoDS_Shape Controls::LyingOnGeom::GetShape()
268 Controls::LyingOnGeom::
274 bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh* theMeshDS,
275 const TopoDS_Shape& theShape,
276 const SMDS_MeshElement* theElem,
277 TopAbs_ShapeEnum theFindShapeEnum,
278 TopAbs_ShapeEnum theAvoidShapeEnum )
280 if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
283 TopTools_IndexedMapOfShape aSubShapes;
284 TopExp::MapShapes( theShape, aSubShapes );
286 for (int i = 1; i <= aSubShapes.Extent(); i++)
288 const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
290 if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
291 if( aSubMesh->Contains( theElem ) )
294 SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
295 while ( aNodeIt->more() )
297 const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
298 SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
299 while ( anElemIt->more() )
301 const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
302 if (anElement == theElem)
318 MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh )
320 SMESH_Mesh_i* anImplPtr = DownCast<SMESH_Mesh_i*>(theMesh);
321 return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0;
326 toArray( const TColStd_ListOfInteger& aList )
328 SMESH::long_array_var anArray = new SMESH::long_array;
329 anArray->length( aList.Extent() );
330 TColStd_ListIteratorOfListOfInteger anIter( aList );
332 for( ; anIter.More(); anIter.Next() )
333 anArray[ i++ ] = anIter.Value();
335 return anArray._retn();
340 toArray( const TColStd_ListOfReal& aList )
342 SMESH::double_array_var anArray = new SMESH::double_array;
343 anArray->length( aList.Extent() );
344 TColStd_ListIteratorOfListOfReal anIter( aList );
346 for( ; anIter.More(); anIter.Next() )
347 anArray[ i++ ] = anIter.Value();
349 return anArray._retn();
352 static SMESH::Filter::Criterion createCriterion()
354 SMESH::Filter::Criterion aCriterion;
356 aCriterion.Type = FT_Undefined;
357 aCriterion.Compare = FT_Undefined;
358 aCriterion.Threshold = 0;
359 aCriterion.UnaryOp = FT_Undefined;
360 aCriterion.BinaryOp = FT_Undefined;
361 aCriterion.ThresholdStr = "";
362 aCriterion.ThresholdID = "";
363 aCriterion.Tolerance = Precision::Confusion();
364 aCriterion.TypeOfElement = SMESH::ALL;
365 aCriterion.Precision = -1;
370 static TopoDS_Shape getShapeByName( const char* theName )
374 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
375 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
376 if (!CORBA::is_nil(aStudy))
378 SALOMEDS::Study::ListOfSObject_var aList =
379 aStudy->FindObjectByName( theName, "GEOM" );
380 if ( aList->length() > 0 )
382 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
383 if ( !aGeomObj->_is_nil() )
385 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
386 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
392 return TopoDS_Shape();
395 static TopoDS_Shape getShapeByID (const char* theID)
397 if (theID != 0 && theID != "") {
398 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
399 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
401 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
402 SALOMEDS::GenericAttribute_var anAttr;
403 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) {
404 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
405 CORBA::String_var aVal = anIOR->Value();
406 CORBA::Object_var obj = aStudy->ConvertIORToObject(aVal);
407 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
409 if (!aGeomObj->_is_nil()) {
410 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
411 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj );
417 return TopoDS_Shape();
420 static char* getShapeNameByID (const char* theID)
424 if (theID != 0 && theID != "") {
425 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
426 SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
428 //SALOMEDS::SObject_var aSObj = aStudy->FindObjectIOR( theID );
429 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theID);
430 SALOMEDS::GenericAttribute_var anAttr;
431 if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeName")) {
432 SALOMEDS::AttributeName_var aNameAttr = SALOMEDS::AttributeName::_narrow(anAttr);
433 aName = aNameAttr->Value();
447 Description : An abstact class for all functors
449 Functor_i::Functor_i():
450 SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
452 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
453 //PortableServer::ObjectId_var anObjectId =
454 // SMESH_Gen_i::GetPOA()->activate_object( this );
457 Functor_i::~Functor_i()
459 //TPythonDump()<<this<<".Destroy()";
462 void Functor_i::SetMesh( SMESH_Mesh_ptr theMesh )
464 myFunctorPtr->SetMesh( MeshPtr2SMDSMesh( theMesh ) );
465 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
468 ElementType Functor_i::GetElementType()
470 return ( ElementType )myFunctorPtr->GetType();
475 Class : NumericalFunctor_i
476 Description : Base class for numerical functors
478 CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
480 return myNumericalFunctorPtr->GetValue( theId );
483 void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision )
485 myNumericalFunctorPtr->SetPrecision( thePrecision );
486 TPythonDump()<<this<<".SetPrecision("<<thePrecision<<")";
489 CORBA::Long NumericalFunctor_i::GetPrecision()
491 return myNumericalFunctorPtr->GetPrecision();
494 Controls::NumericalFunctorPtr NumericalFunctor_i::GetNumericalFunctor()
496 return myNumericalFunctorPtr;
501 Class : SMESH_MinimumAngle
502 Description : Functor for calculation of minimum angle
504 MinimumAngle_i::MinimumAngle_i()
506 myNumericalFunctorPtr.reset( new Controls::MinimumAngle() );
507 myFunctorPtr = myNumericalFunctorPtr;
510 FunctorType MinimumAngle_i::GetFunctorType()
512 return SMESH::FT_MinimumAngle;
518 Description : Functor for calculating aspect ratio
520 AspectRatio_i::AspectRatio_i()
522 myNumericalFunctorPtr.reset( new Controls::AspectRatio() );
523 myFunctorPtr = myNumericalFunctorPtr;
526 FunctorType AspectRatio_i::GetFunctorType()
528 return SMESH::FT_AspectRatio;
533 Class : AspectRatio3D
534 Description : Functor for calculating aspect ratio 3D
536 AspectRatio3D_i::AspectRatio3D_i()
538 myNumericalFunctorPtr.reset( new Controls::AspectRatio3D() );
539 myFunctorPtr = myNumericalFunctorPtr;
542 FunctorType AspectRatio3D_i::GetFunctorType()
544 return SMESH::FT_AspectRatio3D;
550 Description : Functor for calculating warping
552 Warping_i::Warping_i()
554 myNumericalFunctorPtr.reset( new Controls::Warping() );
555 myFunctorPtr = myNumericalFunctorPtr;
558 FunctorType Warping_i::GetFunctorType()
560 return SMESH::FT_Warping;
566 Description : Functor for calculating taper
570 myNumericalFunctorPtr.reset( new Controls::Taper() );
571 myFunctorPtr = myNumericalFunctorPtr;
574 FunctorType Taper_i::GetFunctorType()
576 return SMESH::FT_Taper;
582 Description : Functor for calculating skew in degrees
586 myNumericalFunctorPtr.reset( new Controls::Skew() );
587 myFunctorPtr = myNumericalFunctorPtr;
590 FunctorType Skew_i::GetFunctorType()
592 return SMESH::FT_Skew;
597 Description : Functor for calculating area
601 myNumericalFunctorPtr.reset( new Controls::Area() );
602 myFunctorPtr = myNumericalFunctorPtr;
605 FunctorType Area_i::GetFunctorType()
607 return SMESH::FT_Area;
612 Description : Functor for calculating volume of 3D element
614 Volume3D_i::Volume3D_i()
616 myNumericalFunctorPtr.reset( new Controls::Volume() );
617 myFunctorPtr = myNumericalFunctorPtr;
620 FunctorType Volume3D_i::GetFunctorType()
622 return SMESH::FT_Volume3D;
627 Description : Functor for calculating length off edge
631 myNumericalFunctorPtr.reset( new Controls::Length() );
632 myFunctorPtr = myNumericalFunctorPtr;
635 FunctorType Length_i::GetFunctorType()
637 return SMESH::FT_Length;
642 Description : Functor for calculating length of edge
644 Length2D_i::Length2D_i()
646 myNumericalFunctorPtr.reset( new Controls::Length2D() );
647 myFunctorPtr = myNumericalFunctorPtr;
650 FunctorType Length2D_i::GetFunctorType()
652 return SMESH::FT_Length2D;
655 SMESH::Length2D::Values* Length2D_i::GetValues()
657 INFOS("Length2D_i::GetValues");
658 SMESH::Controls::Length2D::TValues aValues;
659 myLength2DPtr->GetValues( aValues );
661 long i = 0, iEnd = aValues.size();
663 SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd);
665 SMESH::Controls::Length2D::TValues::const_iterator anIter;
666 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
668 const SMESH::Controls::Length2D::Value& aVal = *anIter;
669 SMESH::Length2D::Value &aValue = aResult[ i ];
671 aValue.myLength = aVal.myLength;
672 aValue.myPnt1 = aVal.myPntId[ 0 ];
673 aValue.myPnt2 = aVal.myPntId[ 1 ];
676 INFOS("Length2D_i::GetValuess~");
677 return aResult._retn();
681 Class : MultiConnection_i
682 Description : Functor for calculating number of faces conneted to the edge
684 MultiConnection_i::MultiConnection_i()
686 myNumericalFunctorPtr.reset( new Controls::MultiConnection() );
687 myFunctorPtr = myNumericalFunctorPtr;
690 FunctorType MultiConnection_i::GetFunctorType()
692 return SMESH::FT_MultiConnection;
696 Class : MultiConnection2D_i
697 Description : Functor for calculating number of faces conneted to the edge
699 MultiConnection2D_i::MultiConnection2D_i()
701 myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() );
702 myFunctorPtr = myNumericalFunctorPtr;
705 FunctorType MultiConnection2D_i::GetFunctorType()
707 return SMESH::FT_MultiConnection2D;
710 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
712 INFOS("MultiConnection2D_i::GetValues");
713 SMESH::Controls::MultiConnection2D::MValues aValues;
714 myMulticonnection2DPtr->GetValues( aValues );
716 long i = 0, iEnd = aValues.size();
718 SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd);
720 SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter;
721 for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
723 const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first;
724 SMESH::MultiConnection2D::Value &aValue = aResult[ i ];
726 aValue.myPnt1 = aVal.myPntId[ 0 ];
727 aValue.myPnt2 = aVal.myPntId[ 1 ];
728 aValue.myNbConnects = (*anIter).second;
731 INFOS("Multiconnection2D_i::GetValuess~");
732 return aResult._retn();
742 Description : Base class for all predicates
744 CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
746 return myPredicatePtr->IsSatisfy( theId );
749 Controls::PredicatePtr Predicate_i::GetPredicate()
751 return myPredicatePtr;
755 Class : BadOrientedVolume_i
756 Description : Verify whether a mesh volume is incorrectly oriented from
757 the point of view of MED convention
759 BadOrientedVolume_i::BadOrientedVolume_i()
761 Controls::PredicatePtr control( new Controls::BadOrientedVolume() );
762 myFunctorPtr = myPredicatePtr = control;
765 FunctorType BadOrientedVolume_i::GetFunctorType()
767 return SMESH::FT_BadOrientedVolume;
771 Class : BelongToGeom_i
772 Description : Predicate for selection on geometrical support
774 BelongToGeom_i::BelongToGeom_i()
776 myBelongToGeomPtr.reset( new Controls::BelongToGeom() );
777 myFunctorPtr = myPredicatePtr = myBelongToGeomPtr;
782 BelongToGeom_i::~BelongToGeom_i()
788 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
790 if ( theGeom->_is_nil() )
792 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
793 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
794 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
795 myBelongToGeomPtr->SetGeom( aLocShape );
796 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
799 void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
801 myBelongToGeomPtr->SetGeom( theShape );
804 void BelongToGeom_i::SetElementType(ElementType theType){
805 myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
806 TPythonDump()<<this<<".SetElementType("<<theType<<")";
809 FunctorType BelongToGeom_i::GetFunctorType()
811 return SMESH::FT_BelongToGeom;
814 void BelongToGeom_i::SetShapeName( const char* theName )
817 myShapeName = strdup( theName );
818 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
819 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
822 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
825 myShapeName = strdup( theName );
828 myShapeID = strdup( theID );
832 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
833 myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
835 myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
838 char* BelongToGeom_i::GetShapeName()
840 return CORBA::string_dup( myShapeName );
843 char* BelongToGeom_i::GetShapeID()
845 return CORBA::string_dup( myShapeID );
849 Class : BelongToSurface_i
850 Description : Predicate for selection on geometrical support
852 BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceType )
854 myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() );
855 myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr;
858 mySurfaceType = theSurfaceType;
861 BelongToSurface_i::~BelongToSurface_i()
867 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
869 if ( theGeom->_is_nil() )
871 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
872 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
873 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
875 if ( aLocShape.ShapeType() == TopAbs_FACE )
877 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aLocShape ) );
878 if ( !aSurf.IsNull() && aSurf->DynamicType() == mySurfaceType )
880 myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
885 myElementsOnSurfacePtr->SetSurface( TopoDS_Shape(), (SMDSAbs_ElementType)theType );
888 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
891 myShapeName = strdup( theName );
892 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
893 TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
896 void BelongToSurface_i::SetShape( const char* theID, const char* theName, ElementType theType )
899 myShapeName = strdup( theName );
902 myShapeID = strdup( theID );
906 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
907 myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
909 myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
912 char* BelongToSurface_i::GetShapeName()
914 return CORBA::string_dup( myShapeName );
917 char* BelongToSurface_i::GetShapeID()
919 return CORBA::string_dup( myShapeID );
922 void BelongToSurface_i::SetTolerance( CORBA::Double theToler )
924 myElementsOnSurfacePtr->SetTolerance( theToler );
925 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
928 CORBA::Double BelongToSurface_i::GetTolerance()
930 return myElementsOnSurfacePtr->GetTolerance();
933 void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions )
935 myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions );
936 TPythonDump()<<this<<".SetUseBoundaries( " << theUseBndRestrictions << " )";
939 CORBA::Boolean BelongToSurface_i::GetUseBoundaries()
941 return myElementsOnSurfacePtr->GetUseBoundaries();
946 Class : BelongToPlane_i
947 Description : Verify whether mesh element lie in pointed Geom planar object
950 BelongToPlane_i::BelongToPlane_i()
951 : BelongToSurface_i( STANDARD_TYPE( Geom_Plane ) )
955 void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
957 BelongToSurface_i::SetSurface( theGeom, theType );
958 TPythonDump()<<this<<".SetPlane("<<theGeom<<","<<theType<<")";
961 FunctorType BelongToPlane_i::GetFunctorType()
963 return FT_BelongToPlane;
967 Class : BelongToCylinder_i
968 Description : Verify whether mesh element lie in pointed Geom planar object
971 BelongToCylinder_i::BelongToCylinder_i()
972 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
976 void BelongToCylinder_i::SetCylinder( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
978 BelongToSurface_i::SetSurface( theGeom, theType );
979 TPythonDump()<<this<<".SetCylinder("<<theGeom<<","<<theType<<")";
982 FunctorType BelongToCylinder_i::GetFunctorType()
984 return FT_BelongToCylinder;
988 Class : BelongToGenSurface_i
989 Description : Verify whether mesh element lie in pointed Geom planar object
992 BelongToGenSurface_i::BelongToGenSurface_i()
993 : BelongToSurface_i( STANDARD_TYPE( Geom_CylindricalSurface ) )
997 void BelongToGenSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
999 if ( theGeom->_is_nil() )
1001 TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
1002 if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE )
1003 aLocShape.Nullify();
1005 BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType );
1006 TPythonDump()<<this<<".SetGenSurface("<<theGeom<<","<<theType<<")";
1009 FunctorType BelongToGenSurface_i::GetFunctorType()
1011 return FT_BelongToGenSurface;
1015 Class : LyingOnGeom_i
1016 Description : Predicate for selection on geometrical support
1018 LyingOnGeom_i::LyingOnGeom_i()
1020 myLyingOnGeomPtr.reset( new Controls::LyingOnGeom() );
1021 myFunctorPtr = myPredicatePtr = myLyingOnGeomPtr;
1026 LyingOnGeom_i::~LyingOnGeom_i()
1032 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
1034 if ( theGeom->_is_nil() )
1036 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1037 GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
1038 TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
1039 myLyingOnGeomPtr->SetGeom( aLocShape );
1040 TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
1043 void LyingOnGeom_i::SetGeom( const TopoDS_Shape& theShape )
1045 myLyingOnGeomPtr->SetGeom( theShape );
1048 void LyingOnGeom_i::SetElementType(ElementType theType){
1049 myLyingOnGeomPtr->SetType(SMDSAbs_ElementType(theType));
1050 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1053 FunctorType LyingOnGeom_i::GetFunctorType()
1055 return SMESH::FT_LyingOnGeom;
1058 void LyingOnGeom_i::SetShapeName( const char* theName )
1061 myShapeName = strdup( theName );
1062 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1063 TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
1066 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
1069 myShapeName = strdup( theName );
1072 myShapeID = strdup( theID );
1076 if ( myShapeID && strcmp(myShapeName, getShapeNameByID(myShapeID)) == 0 )
1077 myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
1079 myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
1082 char* LyingOnGeom_i::GetShapeName()
1084 return CORBA::string_dup( myShapeName );
1087 char* LyingOnGeom_i::GetShapeID()
1089 return CORBA::string_dup( myShapeID );
1093 Class : FreeBorders_i
1094 Description : Predicate for free borders
1096 FreeBorders_i::FreeBorders_i()
1098 myPredicatePtr.reset(new Controls::FreeBorders());
1099 myFunctorPtr = myPredicatePtr;
1102 FunctorType FreeBorders_i::GetFunctorType()
1104 return SMESH::FT_FreeBorders;
1109 Description : Predicate for free borders
1111 FreeEdges_i::FreeEdges_i()
1112 : myFreeEdgesPtr( new Controls::FreeEdges() )
1114 myFunctorPtr = myPredicatePtr = myFreeEdgesPtr;
1117 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
1119 INFOS("FreeEdges_i::GetBorders");
1120 SMESH::Controls::FreeEdges::TBorders aBorders;
1121 myFreeEdgesPtr->GetBoreders( aBorders );
1123 long i = 0, iEnd = aBorders.size();
1125 SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders;
1126 aResult->length(iEnd);
1128 SMESH::Controls::FreeEdges::TBorders::const_iterator anIter;
1129 for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ )
1131 const SMESH::Controls::FreeEdges::Border& aBord = *anIter;
1132 SMESH::FreeEdges::Border &aBorder = aResult[ i ];
1134 aBorder.myElemId = aBord.myElemId;
1135 aBorder.myPnt1 = aBord.myPntId[ 0 ];
1136 aBorder.myPnt2 = aBord.myPntId[ 1 ];
1139 INFOS("FreeEdges_i::GetBorders~");
1140 return aResult._retn();
1143 FunctorType FreeEdges_i::GetFunctorType()
1145 return SMESH::FT_FreeEdges;
1149 Class : RangeOfIds_i
1150 Description : Predicate for Range of Ids.
1151 Range may be specified with two ways.
1152 1. Using AddToRange method
1153 2. With SetRangeStr method. Parameter of this method is a string
1154 like as "1,2,3,50-60,63,67,70-"
1157 RangeOfIds_i::RangeOfIds_i()
1159 myRangeOfIdsPtr.reset( new Controls::RangeOfIds() );
1160 myFunctorPtr = myPredicatePtr = myRangeOfIdsPtr;
1163 void RangeOfIds_i::SetRange( const SMESH::long_array& theIds )
1165 CORBA::Long iEnd = theIds.length();
1166 for ( CORBA::Long i = 0; i < iEnd; i++ )
1167 myRangeOfIdsPtr->AddToRange( theIds[ i ] );
1168 TPythonDump()<<this<<".SetRange("<<theIds<<")";
1171 CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange )
1173 TPythonDump()<<this<<".SetRangeStr('"<<theRange<<"')";
1174 return myRangeOfIdsPtr->SetRangeStr(
1175 TCollection_AsciiString( (Standard_CString)theRange ) );
1178 char* RangeOfIds_i::GetRangeStr()
1180 TCollection_AsciiString aStr;
1181 myRangeOfIdsPtr->GetRangeStr( aStr );
1182 return CORBA::string_dup( aStr.ToCString() );
1185 void RangeOfIds_i::SetElementType( ElementType theType )
1187 myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) );
1188 TPythonDump()<<this<<".SetElementType("<<theType<<")";
1191 FunctorType RangeOfIds_i::GetFunctorType()
1193 return SMESH::FT_RangeOfIds;
1197 Class : Comparator_i
1198 Description : Base class for comparators
1200 Comparator_i::Comparator_i():
1201 myNumericalFunctor( NULL )
1204 Comparator_i::~Comparator_i()
1206 if ( myNumericalFunctor )
1207 myNumericalFunctor->Destroy();
1210 void Comparator_i::SetMargin( CORBA::Double theValue )
1212 myComparatorPtr->SetMargin( theValue );
1213 TPythonDump()<<this<<".SetMargin("<<theValue<<")";
1216 CORBA::Double Comparator_i::GetMargin()
1218 return myComparatorPtr->GetMargin();
1221 void Comparator_i::SetNumFunctor( NumericalFunctor_ptr theFunct )
1223 if ( myNumericalFunctor )
1224 myNumericalFunctor->Destroy();
1226 myNumericalFunctor = DownCast<NumericalFunctor_i*>(theFunct);
1228 if ( myNumericalFunctor )
1230 myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() );
1231 myNumericalFunctor->Register();
1232 TPythonDump()<<this<<".SetNumFunctor("<<myNumericalFunctor<<")";
1236 Controls::ComparatorPtr Comparator_i::GetComparator()
1238 return myComparatorPtr;
1241 NumericalFunctor_i* Comparator_i::GetNumFunctor_i()
1243 return myNumericalFunctor;
1249 Description : Comparator "<"
1251 LessThan_i::LessThan_i()
1253 myComparatorPtr.reset( new Controls::LessThan() );
1254 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1257 FunctorType LessThan_i::GetFunctorType()
1259 return SMESH::FT_LessThan;
1265 Description : Comparator ">"
1267 MoreThan_i::MoreThan_i()
1269 myComparatorPtr.reset( new Controls::MoreThan() );
1270 myFunctorPtr = myPredicatePtr = myComparatorPtr;
1273 FunctorType MoreThan_i::GetFunctorType()
1275 return SMESH::FT_MoreThan;
1281 Description : Comparator "="
1283 EqualTo_i::EqualTo_i()
1284 : myEqualToPtr( new Controls::EqualTo() )
1286 myFunctorPtr = myPredicatePtr = myComparatorPtr = myEqualToPtr;
1289 void EqualTo_i::SetTolerance( CORBA::Double theToler )
1291 myEqualToPtr->SetTolerance( theToler );
1292 TPythonDump()<<this<<".SetTolerance("<<theToler<<")";
1295 CORBA::Double EqualTo_i::GetTolerance()
1297 return myEqualToPtr->GetTolerance();
1300 FunctorType EqualTo_i::GetFunctorType()
1302 return SMESH::FT_EqualTo;
1306 Class : LogicalNOT_i
1307 Description : Logical NOT predicate
1309 LogicalNOT_i::LogicalNOT_i()
1310 : myPredicate( NULL ),
1311 myLogicalNOTPtr( new Controls::LogicalNOT() )
1313 myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
1316 LogicalNOT_i::~LogicalNOT_i()
1319 myPredicate->Destroy();
1322 void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate )
1325 myPredicate->Destroy();
1327 myPredicate = SMESH::GetPredicate(thePredicate);
1330 myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate());
1331 myPredicate->Register();
1332 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1336 FunctorType LogicalNOT_i::GetFunctorType()
1338 return SMESH::FT_LogicalNOT;
1341 Predicate_i* LogicalNOT_i::GetPredicate_i()
1348 Class : LogicalBinary_i
1349 Description : Base class for binary logical predicate
1351 LogicalBinary_i::LogicalBinary_i()
1352 : myPredicate1( NULL ),
1353 myPredicate2( NULL )
1356 LogicalBinary_i::~LogicalBinary_i()
1359 myPredicate1->Destroy();
1362 myPredicate2->Destroy();
1365 void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh )
1368 myPredicate1->SetMesh( theMesh );
1371 myPredicate2->SetMesh( theMesh );
1374 void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate )
1377 myPredicate1->Destroy();
1379 myPredicate1 = SMESH::GetPredicate(thePredicate);
1381 if ( myPredicate1 ){
1382 myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate());
1383 myPredicate1->Register();
1384 TPythonDump()<<this<<".SetPredicate1("<<myPredicate1<<")";
1388 void LogicalBinary_i::SetPredicate2( Predicate_ptr thePredicate )
1391 myPredicate2->Destroy();
1393 myPredicate2 = SMESH::GetPredicate(thePredicate);
1395 if ( myPredicate2 ){
1396 myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate());
1397 myPredicate2->Register();
1398 TPythonDump()<<this<<".SetPredicate2("<<myPredicate2<<")";
1402 Controls::LogicalBinaryPtr LogicalBinary_i::GetLogicalBinary()
1404 return myLogicalBinaryPtr;
1407 Predicate_i* LogicalBinary_i::GetPredicate1_i()
1409 return myPredicate1;
1411 Predicate_i* LogicalBinary_i::GetPredicate2_i()
1413 return myPredicate2;
1418 Class : LogicalAND_i
1419 Description : Logical AND
1421 LogicalAND_i::LogicalAND_i()
1423 myLogicalBinaryPtr.reset( new Controls::LogicalAND() );
1424 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1427 FunctorType LogicalAND_i::GetFunctorType()
1429 return SMESH::FT_LogicalAND;
1435 Description : Logical OR
1437 LogicalOR_i::LogicalOR_i()
1439 myLogicalBinaryPtr.reset( new Controls::LogicalOR() );
1440 myFunctorPtr = myPredicatePtr = myLogicalBinaryPtr;
1443 FunctorType LogicalOR_i::GetFunctorType()
1445 return SMESH::FT_LogicalOR;
1453 FilterManager_i::FilterManager_i()
1454 : SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
1456 //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method
1457 //PortableServer::ObjectId_var anObjectId =
1458 // SMESH_Gen_i::GetPOA()->activate_object( this );
1462 FilterManager_i::~FilterManager_i()
1464 //TPythonDump()<<this<<".Destroy()";
1468 MinimumAngle_ptr FilterManager_i::CreateMinimumAngle()
1470 SMESH::MinimumAngle_i* aServant = new SMESH::MinimumAngle_i();
1471 SMESH::MinimumAngle_var anObj = aServant->_this();
1472 TPythonDump()<<aServant<<" = "<<this<<".CreateMinimumAngle()";
1473 return anObj._retn();
1477 AspectRatio_ptr FilterManager_i::CreateAspectRatio()
1479 SMESH::AspectRatio_i* aServant = new SMESH::AspectRatio_i();
1480 SMESH::AspectRatio_var anObj = aServant->_this();
1481 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio()";
1482 return anObj._retn();
1486 AspectRatio3D_ptr FilterManager_i::CreateAspectRatio3D()
1488 SMESH::AspectRatio3D_i* aServant = new SMESH::AspectRatio3D_i();
1489 SMESH::AspectRatio3D_var anObj = aServant->_this();
1490 TPythonDump()<<aServant<<" = "<<this<<".CreateAspectRatio3D()";
1491 return anObj._retn();
1495 Warping_ptr FilterManager_i::CreateWarping()
1497 SMESH::Warping_i* aServant = new SMESH::Warping_i();
1498 SMESH::Warping_var anObj = aServant->_this();
1499 TPythonDump()<<aServant<<" = "<<this<<".CreateWarping()";
1500 return anObj._retn();
1504 Taper_ptr FilterManager_i::CreateTaper()
1506 SMESH::Taper_i* aServant = new SMESH::Taper_i();
1507 SMESH::Taper_var anObj = aServant->_this();
1508 TPythonDump()<<aServant<<" = "<<this<<".CreateTaper()";
1509 return anObj._retn();
1513 Skew_ptr FilterManager_i::CreateSkew()
1515 SMESH::Skew_i* aServant = new SMESH::Skew_i();
1516 SMESH::Skew_var anObj = aServant->_this();
1517 TPythonDump()<<aServant<<" = "<<this<<".CreateSkew()";
1518 return anObj._retn();
1522 Area_ptr FilterManager_i::CreateArea()
1524 SMESH::Area_i* aServant = new SMESH::Area_i();
1525 SMESH::Area_var anObj = aServant->_this();
1526 TPythonDump()<<aServant<<" = "<<this<<".CreateArea()";
1527 return anObj._retn();
1531 Volume3D_ptr FilterManager_i::CreateVolume3D()
1533 SMESH::Volume3D_i* aServant = new SMESH::Volume3D_i();
1534 SMESH::Volume3D_var anObj = aServant->_this();
1535 TPythonDump()<<aServant<<" = "<<this<<".CreateVolume3D()";
1536 return anObj._retn();
1540 Length_ptr FilterManager_i::CreateLength()
1542 SMESH::Length_i* aServant = new SMESH::Length_i();
1543 SMESH::Length_var anObj = aServant->_this();
1544 TPythonDump()<<aServant<<" = "<<this<<".CreateLength()";
1545 return anObj._retn();
1548 Length2D_ptr FilterManager_i::CreateLength2D()
1550 SMESH::Length2D_i* aServant = new SMESH::Length2D_i();
1551 SMESH::Length2D_var anObj = aServant->_this();
1552 TPythonDump()<<aServant<<" = "<<this<<".CreateLength2D()";
1553 return anObj._retn();
1556 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
1558 SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
1559 SMESH::MultiConnection_var anObj = aServant->_this();
1560 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection()";
1561 return anObj._retn();
1564 MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D()
1566 SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i();
1567 SMESH::MultiConnection2D_var anObj = aServant->_this();
1568 TPythonDump()<<aServant<<" = "<<this<<".CreateMultiConnection2D()";
1569 return anObj._retn();
1572 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
1574 SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
1575 SMESH::BelongToGeom_var anObj = aServant->_this();
1576 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGeom()";
1577 return anObj._retn();
1580 BelongToPlane_ptr FilterManager_i::CreateBelongToPlane()
1582 SMESH::BelongToPlane_i* aServant = new SMESH::BelongToPlane_i();
1583 SMESH::BelongToPlane_var anObj = aServant->_this();
1584 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToPlane()";
1585 return anObj._retn();
1588 BelongToCylinder_ptr FilterManager_i::CreateBelongToCylinder()
1590 SMESH::BelongToCylinder_i* aServant = new SMESH::BelongToCylinder_i();
1591 SMESH::BelongToCylinder_var anObj = aServant->_this();
1592 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToCylinder()";
1593 return anObj._retn();
1596 BelongToGenSurface_ptr FilterManager_i::CreateBelongToGenSurface()
1598 SMESH::BelongToGenSurface_i* aServant = new SMESH::BelongToGenSurface_i();
1599 SMESH::BelongToGenSurface_var anObj = aServant->_this();
1600 TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToGenSurface()";
1601 return anObj._retn();
1604 LyingOnGeom_ptr FilterManager_i::CreateLyingOnGeom()
1606 SMESH::LyingOnGeom_i* aServant = new SMESH::LyingOnGeom_i();
1607 SMESH::LyingOnGeom_var anObj = aServant->_this();
1608 TPythonDump()<<aServant<<" = "<<this<<".CreateLyingOnGeom()";
1609 return anObj._retn();
1612 FreeBorders_ptr FilterManager_i::CreateFreeBorders()
1614 SMESH::FreeBorders_i* aServant = new SMESH::FreeBorders_i();
1615 SMESH::FreeBorders_var anObj = aServant->_this();
1616 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeBorders()";
1617 return anObj._retn();
1620 FreeEdges_ptr FilterManager_i::CreateFreeEdges()
1622 SMESH::FreeEdges_i* aServant = new SMESH::FreeEdges_i();
1623 SMESH::FreeEdges_var anObj = aServant->_this();
1624 TPythonDump()<<aServant<<" = "<<this<<".CreateFreeEdges()";
1625 return anObj._retn();
1628 RangeOfIds_ptr FilterManager_i::CreateRangeOfIds()
1630 SMESH::RangeOfIds_i* aServant = new SMESH::RangeOfIds_i();
1631 SMESH::RangeOfIds_var anObj = aServant->_this();
1632 TPythonDump()<<aServant<<" = "<<this<<".CreateRangeOfIds()";
1633 return anObj._retn();
1636 BadOrientedVolume_ptr FilterManager_i::CreateBadOrientedVolume()
1638 SMESH::BadOrientedVolume_i* aServant = new SMESH::BadOrientedVolume_i();
1639 SMESH::BadOrientedVolume_var anObj = aServant->_this();
1640 TPythonDump()<<aServant<<" = "<<this<<".CreateBadOrientedVolume()";
1641 return anObj._retn();
1644 LessThan_ptr FilterManager_i::CreateLessThan()
1646 SMESH::LessThan_i* aServant = new SMESH::LessThan_i();
1647 SMESH::LessThan_var anObj = aServant->_this();
1648 TPythonDump()<<aServant<<" = "<<this<<".CreateLessThan()";
1649 return anObj._retn();
1653 MoreThan_ptr FilterManager_i::CreateMoreThan()
1655 SMESH::MoreThan_i* aServant = new SMESH::MoreThan_i();
1656 SMESH::MoreThan_var anObj = aServant->_this();
1657 TPythonDump()<<aServant<<" = "<<this<<".CreateMoreThan()";
1658 return anObj._retn();
1661 EqualTo_ptr FilterManager_i::CreateEqualTo()
1663 SMESH::EqualTo_i* aServant = new SMESH::EqualTo_i();
1664 SMESH::EqualTo_var anObj = aServant->_this();
1665 TPythonDump()<<aServant<<" = "<<this<<".CreateEqualTo()";
1666 return anObj._retn();
1670 LogicalNOT_ptr FilterManager_i::CreateLogicalNOT()
1672 SMESH::LogicalNOT_i* aServant = new SMESH::LogicalNOT_i();
1673 SMESH::LogicalNOT_var anObj = aServant->_this();
1674 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalNOT()";
1675 return anObj._retn();
1679 LogicalAND_ptr FilterManager_i::CreateLogicalAND()
1681 SMESH::LogicalAND_i* aServant = new SMESH::LogicalAND_i();
1682 SMESH::LogicalAND_var anObj = aServant->_this();
1683 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalAND()";
1684 return anObj._retn();
1688 LogicalOR_ptr FilterManager_i::CreateLogicalOR()
1690 SMESH::LogicalOR_i* aServant = new SMESH::LogicalOR_i();
1691 SMESH::LogicalOR_var anObj = aServant->_this();
1692 TPythonDump()<<aServant<<" = "<<this<<".CreateLogicalOR()";
1693 return anObj._retn();
1696 Filter_ptr FilterManager_i::CreateFilter()
1698 SMESH::Filter_i* aServant = new SMESH::Filter_i();
1699 SMESH::Filter_var anObj = aServant->_this();
1700 TPythonDump()<<aServant<<" = "<<this<<".CreateFilter()";
1701 return anObj._retn();
1704 FilterLibrary_ptr FilterManager_i::LoadLibrary( const char* aFileName )
1706 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i( aFileName );
1707 SMESH::FilterLibrary_var anObj = aServant->_this();
1708 TPythonDump()<<aServant<<" = "<<this<<".LoadLibrary("<<aFileName<<")";
1709 return anObj._retn();
1712 FilterLibrary_ptr FilterManager_i::CreateLibrary()
1714 SMESH::FilterLibrary_i* aServant = new SMESH::FilterLibrary_i();
1715 SMESH::FilterLibrary_var anObj = aServant->_this();
1716 TPythonDump()<<aServant<<" = "<<this<<".CreateLibrary()";
1717 return anObj._retn();
1720 CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName )
1722 TPythonDump()<<this<<".DeleteLibrary("<<aFileName<<")";
1723 return remove( aFileName ) ? false : true;
1726 //=============================================================================
1728 * SMESH_Gen_i::CreateFilterManager
1730 * Create filter manager
1732 //=============================================================================
1734 SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager()
1736 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
1737 SMESH::FilterManager_var anObj = aFilter->_this();
1738 return anObj._retn();
1746 //=======================================================================
1747 // name : Filter_i::Filter_i
1748 // Purpose : Constructor
1749 //=======================================================================
1750 Filter_i::Filter_i()
1751 : myPredicate( NULL )
1754 //=======================================================================
1755 // name : Filter_i::~Filter_i
1756 // Purpose : Destructor
1757 //=======================================================================
1758 Filter_i::~Filter_i()
1761 myPredicate->Destroy();
1763 if(!CORBA::is_nil(myMesh))
1766 //TPythonDump()<<this<<".Destroy()";
1769 //=======================================================================
1770 // name : Filter_i::SetPredicate
1771 // Purpose : Set predicate
1772 //=======================================================================
1773 void Filter_i::SetPredicate( Predicate_ptr thePredicate )
1776 myPredicate->Destroy();
1778 myPredicate = SMESH::GetPredicate(thePredicate);
1782 myFilter.SetPredicate( myPredicate->GetPredicate() );
1783 myPredicate->Register();
1784 TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
1788 //=======================================================================
1789 // name : Filter_i::GetElementType
1790 // Purpose : Get entity type
1791 //=======================================================================
1792 SMESH::ElementType Filter_i::GetElementType()
1794 return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL;
1797 //=======================================================================
1798 // name : Filter_i::SetMesh
1799 // Purpose : Set mesh
1800 //=======================================================================
1803 SetMesh( SMESH_Mesh_ptr theMesh )
1805 if(!CORBA::is_nil(theMesh))
1806 theMesh->Register();
1808 if(!CORBA::is_nil(myMesh))
1812 TPythonDump()<<this<<".SetMesh("<<theMesh<<")";
1819 return GetElementsId(myMesh);
1822 //=======================================================================
1823 // name : Filter_i::GetElementsId
1824 // Purpose : Get ids of entities
1825 //=======================================================================
1828 GetElementsId( Predicate_i* thePredicate,
1829 const SMDS_Mesh* theMesh,
1830 Controls::Filter::TIdSequence& theSequence )
1833 Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence);
1838 GetElementsId( Predicate_i* thePredicate,
1839 SMESH_Mesh_ptr theMesh,
1840 Controls::Filter::TIdSequence& theSequence )
1843 if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh))
1844 Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence);
1849 GetElementsId( SMESH_Mesh_ptr theMesh )
1851 SMESH::long_array_var anArray = new SMESH::long_array;
1852 if(!CORBA::is_nil(theMesh) && myPredicate){
1853 Controls::Filter::TIdSequence aSequence;
1854 GetElementsId(myPredicate,theMesh,aSequence);
1855 long i = 0, iEnd = aSequence.size();
1856 anArray->length( iEnd );
1857 for ( ; i < iEnd; i++ )
1858 anArray[ i ] = aSequence[i];
1860 return anArray._retn();
1863 //=======================================================================
1864 // name : getCriteria
1865 // Purpose : Retrieve criterions from predicate
1866 //=======================================================================
1867 static inline bool getCriteria( Predicate_i* thePred,
1868 SMESH::Filter::Criteria_out theCriteria )
1870 int aFType = thePred->GetFunctorType();
1874 case FT_FreeBorders:
1877 CORBA::ULong i = theCriteria->length();
1878 theCriteria->length( i + 1 );
1880 theCriteria[ i ] = createCriterion();
1882 theCriteria[ i ].Type = aFType;
1883 theCriteria[ i ].TypeOfElement = thePred->GetElementType();
1886 case FT_BelongToGeom:
1888 BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
1890 CORBA::ULong i = theCriteria->length();
1891 theCriteria->length( i + 1 );
1893 theCriteria[ i ] = createCriterion();
1895 theCriteria[ i ].Type = FT_BelongToGeom;
1896 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1897 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1898 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1902 case FT_BelongToPlane:
1903 case FT_BelongToCylinder:
1904 case FT_BelongToGenSurface:
1906 BelongToSurface_i* aPred = dynamic_cast<BelongToSurface_i*>( thePred );
1908 CORBA::ULong i = theCriteria->length();
1909 theCriteria->length( i + 1 );
1911 theCriteria[ i ] = createCriterion();
1913 theCriteria[ i ].Type = aFType;
1914 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1915 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1916 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1917 theCriteria[ i ].Tolerance = aPred->GetTolerance();
1921 case FT_LyingOnGeom:
1923 LyingOnGeom_i* aPred = dynamic_cast<LyingOnGeom_i*>( thePred );
1925 CORBA::ULong i = theCriteria->length();
1926 theCriteria->length( i + 1 );
1928 theCriteria[ i ] = createCriterion();
1930 theCriteria[ i ].Type = FT_LyingOnGeom;
1931 theCriteria[ i ].ThresholdStr = aPred->GetShapeName();
1932 theCriteria[ i ].ThresholdID = aPred->GetShapeID();
1933 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1939 RangeOfIds_i* aPred = dynamic_cast<RangeOfIds_i*>( thePred );
1941 CORBA::ULong i = theCriteria->length();
1942 theCriteria->length( i + 1 );
1944 theCriteria[ i ] = createCriterion();
1946 theCriteria[ i ].Type = FT_RangeOfIds;
1947 theCriteria[ i ].ThresholdStr = aPred->GetRangeStr();
1948 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1952 case FT_BadOrientedVolume:
1954 BadOrientedVolume_i* aPred = dynamic_cast<BadOrientedVolume_i*>( thePred );
1956 CORBA::ULong i = theCriteria->length();
1957 theCriteria->length( i + 1 );
1959 theCriteria[ i ] = createCriterion();
1961 theCriteria[ i ].Type = FT_BadOrientedVolume;
1962 theCriteria[ i ].TypeOfElement = aPred->GetElementType();
1970 Comparator_i* aCompar = dynamic_cast<Comparator_i*>( thePred );
1972 CORBA::ULong i = theCriteria->length();
1973 theCriteria->length( i + 1 );
1975 theCriteria[ i ] = createCriterion();
1977 theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType();
1978 theCriteria[ i ].Compare = aFType;
1979 theCriteria[ i ].Threshold = aCompar->GetMargin();
1980 theCriteria[ i ].TypeOfElement = aCompar->GetElementType();
1982 if ( aFType == FT_EqualTo )
1984 EqualTo_i* aCompar = dynamic_cast<EqualTo_i*>( thePred );
1985 theCriteria[ i ].Tolerance = aCompar->GetTolerance();
1992 Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
1993 getCriteria( aPred, theCriteria );
1994 theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT;
2001 Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
2002 Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
2003 if ( !getCriteria( aPred1, theCriteria ) )
2005 theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType;
2006 return getCriteria( aPred2, theCriteria );
2016 //=======================================================================
2017 // name : Filter_i::GetCriteria
2018 // Purpose : Retrieve criterions from predicate
2019 //=======================================================================
2020 CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
2022 theCriteria = new SMESH::Filter::Criteria;
2023 return myPredicate != 0 ? getCriteria( myPredicate, theCriteria ) : true;
2026 //=======================================================================
2027 // name : Filter_i::SetCriteria
2028 // Purpose : Create new predicate and set criterions in it
2029 //=======================================================================
2030 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
2032 if ( myPredicate != 0 )
2033 myPredicate->Destroy();
2035 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2036 FilterManager_ptr aFilterMgr = aFilter->_this();
2038 // CREATE two lists ( PREDICATES and LOG OP )
2041 TPythonDump()<<"aCriteria = []";
2042 std::list<SMESH::Predicate_ptr> aPredicates;
2043 std::list<int> aBinaries;
2044 for ( int i = 0, n = theCriteria.length(); i < n; i++ )
2046 int aCriterion = theCriteria[ i ].Type;
2047 int aCompare = theCriteria[ i ].Compare;
2048 double aThreshold = theCriteria[ i ].Threshold;
2049 const char* aThresholdStr = theCriteria[ i ].ThresholdStr;
2050 const char* aThresholdID = theCriteria[ i ].ThresholdID;
2051 int aUnary = theCriteria[ i ].UnaryOp;
2052 int aBinary = theCriteria[ i ].BinaryOp;
2053 double aTolerance = theCriteria[ i ].Tolerance;
2054 ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement;
2055 long aPrecision = theCriteria[ i ].Precision;
2059 pd << "aCriterion = SMESH.Filter.Criterion(" << aCriterion << "," << aCompare
2060 << "," << aThreshold << ",'" << aThresholdStr;
2062 pd << "',salome.ObjectToID(" << aThresholdID
2063 << ")," << aUnary << "," << aBinary << "," << aTolerance
2064 << "," << aTypeOfElem << "," << aPrecision << ")";
2066 pd << "',''," << aUnary << "," << aBinary << "," << aTolerance
2067 << "," << aTypeOfElem << "," << aPrecision << ")";
2070 SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil();
2071 SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil();
2073 switch ( aCriterion )
2077 case SMESH::FT_MultiConnection:
2078 aFunctor = aFilterMgr->CreateMultiConnection();
2080 case SMESH::FT_MultiConnection2D:
2081 aFunctor = aFilterMgr->CreateMultiConnection2D();
2083 case SMESH::FT_Length:
2084 aFunctor = aFilterMgr->CreateLength();
2086 case SMESH::FT_Length2D:
2087 aFunctor = aFilterMgr->CreateLength2D();
2089 case SMESH::FT_AspectRatio:
2090 aFunctor = aFilterMgr->CreateAspectRatio();
2092 case SMESH::FT_AspectRatio3D:
2093 aFunctor = aFilterMgr->CreateAspectRatio3D();
2095 case SMESH::FT_Warping:
2096 aFunctor = aFilterMgr->CreateWarping();
2098 case SMESH::FT_MinimumAngle:
2099 aFunctor = aFilterMgr->CreateMinimumAngle();
2101 case SMESH::FT_Taper:
2102 aFunctor = aFilterMgr->CreateTaper();
2104 case SMESH::FT_Skew:
2105 aFunctor = aFilterMgr->CreateSkew();
2107 case SMESH::FT_Area:
2108 aFunctor = aFilterMgr->CreateArea();
2110 case SMESH::FT_Volume3D:
2111 aFunctor = aFilterMgr->CreateVolume3D();
2116 case SMESH::FT_FreeBorders:
2117 aPredicate = aFilterMgr->CreateFreeBorders();
2119 case SMESH::FT_FreeEdges:
2120 aPredicate = aFilterMgr->CreateFreeEdges();
2122 case SMESH::FT_BelongToGeom:
2124 SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
2125 tmpPred->SetElementType( aTypeOfElem );
2126 tmpPred->SetShape( aThresholdID, aThresholdStr );
2127 aPredicate = tmpPred;
2130 case SMESH::FT_BelongToPlane:
2131 case SMESH::FT_BelongToCylinder:
2132 case SMESH::FT_BelongToGenSurface:
2134 SMESH::BelongToSurface_ptr tmpPred;
2135 switch ( aCriterion ) {
2136 case SMESH::FT_BelongToPlane:
2137 tmpPred = aFilterMgr->CreateBelongToPlane(); break;
2138 case SMESH::FT_BelongToCylinder:
2139 tmpPred = aFilterMgr->CreateBelongToCylinder(); break;
2141 tmpPred = aFilterMgr->CreateBelongToGenSurface();
2143 tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem );
2144 tmpPred->SetTolerance( aTolerance );
2145 aPredicate = tmpPred;
2148 case SMESH::FT_LyingOnGeom:
2150 SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom();
2151 tmpPred->SetElementType( aTypeOfElem );
2152 tmpPred->SetShape( aThresholdID, aThresholdStr );
2153 aPredicate = tmpPred;
2156 case SMESH::FT_RangeOfIds:
2158 SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds();
2159 tmpPred->SetRangeStr( aThresholdStr );
2160 tmpPred->SetElementType( aTypeOfElem );
2161 aPredicate = tmpPred;
2164 case SMESH::FT_BadOrientedVolume:
2166 aPredicate = aFilterMgr->CreateBadOrientedVolume();
2175 if ( !aFunctor->_is_nil() && aPredicate->_is_nil() )
2177 SMESH::Comparator_ptr aComparator = SMESH::Comparator::_nil();
2179 if ( aCompare == SMESH::FT_LessThan )
2180 aComparator = aFilterMgr->CreateLessThan();
2181 else if ( aCompare == SMESH::FT_MoreThan )
2182 aComparator = aFilterMgr->CreateMoreThan();
2183 else if ( aCompare == SMESH::FT_EqualTo )
2184 aComparator = aFilterMgr->CreateEqualTo();
2188 aComparator->SetNumFunctor( aFunctor );
2189 aComparator->SetMargin( aThreshold );
2191 if ( aCompare == FT_EqualTo )
2193 SMESH::EqualTo_var anEqualTo = SMESH::EqualTo::_narrow( aComparator );
2194 anEqualTo->SetTolerance( aTolerance );
2197 aPredicate = aComparator;
2199 aFunctor->SetPrecision( aPrecision );
2203 if ( aUnary == FT_LogicalNOT )
2205 SMESH::LogicalNOT_ptr aNotPred = aFilterMgr->CreateLogicalNOT();
2206 aNotPred->SetPredicate( aPredicate );
2207 aPredicate = aNotPred;
2211 aPredicates.push_back( aPredicate );
2212 aBinaries.push_back( aBinary );
2213 TPythonDump()<<"aCriteria.append(aCriterion)";
2216 TPythonDump()<<this<<".SetCriteria(aCriteria)";
2218 // CREATE ONE PREDICATE FROM PREVIOUSLY CREATED MAP
2220 // combine all "AND" operations
2222 std::list<SMESH::Predicate_ptr> aResList;
2224 std::list<SMESH::Predicate_ptr>::iterator aPredIter;
2225 std::list<int>::iterator aBinaryIter;
2227 SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
2228 int aPrevBinary = SMESH::FT_Undefined;
2230 for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
2231 aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
2232 ++aPredIter, ++aBinaryIter )
2234 int aCurrBinary = *aBinaryIter;
2236 SMESH::Predicate_ptr aCurrPred = SMESH::Predicate::_nil();
2238 if ( aPrevBinary == SMESH::FT_LogicalAND )
2241 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalAND();
2242 aBinaryPred->SetPredicate1( aPrevPredicate );
2243 aBinaryPred->SetPredicate2( *aPredIter );
2244 aCurrPred = aBinaryPred;
2247 aCurrPred = *aPredIter;
2249 if ( aCurrBinary != SMESH::FT_LogicalAND )
2250 aResList.push_back( aCurrPred );
2252 aPrevPredicate = aCurrPred;
2253 aPrevBinary = aCurrBinary;
2256 // combine all "OR" operations
2258 SMESH::Predicate_ptr aResPredicate = SMESH::Predicate::_nil();
2260 if ( aResList.size() == 1 )
2261 aResPredicate = *aResList.begin();
2262 else if ( aResList.size() > 1 )
2264 std::list<SMESH::Predicate_ptr>::iterator anIter = aResList.begin();
2265 aResPredicate = *anIter;
2267 for ( ; anIter != aResList.end(); ++anIter )
2269 SMESH::LogicalBinary_ptr aBinaryPred = aFilterMgr->CreateLogicalOR();
2270 aBinaryPred->SetPredicate1( aResPredicate );
2271 aBinaryPred->SetPredicate2( *anIter );
2272 aResPredicate = aBinaryPred;
2276 SetPredicate( aResPredicate );
2278 return !aResPredicate->_is_nil();
2281 //=======================================================================
2282 // name : Filter_i::GetPredicate_i
2283 // Purpose : Get implementation of predicate
2284 //=======================================================================
2285 Predicate_i* Filter_i::GetPredicate_i()
2290 //=======================================================================
2291 // name : Filter_i::GetPredicate
2292 // Purpose : Get predicate
2293 //=======================================================================
2294 Predicate_ptr Filter_i::GetPredicate()
2296 if ( myPredicate == 0 )
2297 return SMESH::Predicate::_nil();
2300 SMESH::Predicate_var anObj = myPredicate->_this();
2301 return anObj._retn();
2309 #define ATTR_TYPE "type"
2310 #define ATTR_COMPARE "compare"
2311 #define ATTR_THRESHOLD "threshold"
2312 #define ATTR_UNARY "unary"
2313 #define ATTR_BINARY "binary"
2314 #define ATTR_THRESHOLD_STR "threshold_str"
2315 #define ATTR_TOLERANCE "tolerance"
2316 #define ATTR_ELEMENT_TYPE "ElementType"
2318 //=======================================================================
2320 // Purpose : Convert bool to LDOMString
2321 //=======================================================================
2322 static inline LDOMString toString( CORBA::Boolean val )
2324 return val ? "logical not" : "";
2327 //=======================================================================
2329 // Purpose : Convert LDOMString to bool
2330 //=======================================================================
2331 static inline bool toBool( const LDOMString& theStr )
2333 return theStr.equals( "logical not" );
2336 //=======================================================================
2338 // Purpose : Convert double to LDOMString
2339 //=======================================================================
2340 static inline LDOMString toString( CORBA::Double val )
2343 sprintf( a, "%e", val );
2344 return LDOMString( a );
2347 //=======================================================================
2349 // Purpose : Convert LDOMString to double
2350 //=======================================================================
2351 static inline double toDouble( const LDOMString& theStr )
2353 return atof( theStr.GetString() );
2356 //=======================================================================
2358 // Purpose : Convert functor type to LDOMString
2359 //=======================================================================
2360 static inline LDOMString toString( CORBA::Long theType )
2364 case FT_AspectRatio : return "Aspect ratio";
2365 case FT_Warping : return "Warping";
2366 case FT_MinimumAngle : return "Minimum angle";
2367 case FT_Taper : return "Taper";
2368 case FT_Skew : return "Skew";
2369 case FT_Area : return "Area";
2370 case FT_Volume3D : return "Volume3D";
2371 case FT_BelongToGeom : return "Belong to Geom";
2372 case FT_BelongToPlane : return "Belong to Plane";
2373 case FT_BelongToCylinder: return "Belong to Cylinder";
2374 case FT_BelongToGenSurface: return "Belong to Generic Surface";
2375 case FT_LyingOnGeom : return "Lying on Geom";
2376 case FT_BadOrientedVolume: return "Bad Oriented Volume";
2377 case FT_RangeOfIds : return "Range of IDs";
2378 case FT_FreeBorders : return "Free borders";
2379 case FT_FreeEdges : return "Free edges";
2380 case FT_MultiConnection : return "Borders at multi-connections";
2381 case FT_MultiConnection2D: return "Borders at multi-connections 2D";
2382 case FT_Length : return "Length";
2383 case FT_Length2D : return "Length2D";
2384 case FT_LessThan : return "Less than";
2385 case FT_MoreThan : return "More than";
2386 case FT_EqualTo : return "Equal to";
2387 case FT_LogicalNOT : return "Not";
2388 case FT_LogicalAND : return "And";
2389 case FT_LogicalOR : return "Or";
2390 case FT_Undefined : return "";
2391 default : return "";
2395 //=======================================================================
2396 // name : toFunctorType
2397 // Purpose : Convert LDOMString to functor type
2398 //=======================================================================
2399 static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
2401 if ( theStr.equals( "Aspect ratio" ) ) return FT_AspectRatio;
2402 else if ( theStr.equals( "Warping" ) ) return FT_Warping;
2403 else if ( theStr.equals( "Minimum angle" ) ) return FT_MinimumAngle;
2404 else if ( theStr.equals( "Taper" ) ) return FT_Taper;
2405 else if ( theStr.equals( "Skew" ) ) return FT_Skew;
2406 else if ( theStr.equals( "Area" ) ) return FT_Area;
2407 else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D;
2408 else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom;
2409 else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane;
2410 else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder;
2411 else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface;
2412 else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom;
2413 else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders;
2414 else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges;
2415 else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection;
2416 // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
2417 else if ( theStr.equals( "Length" ) ) return FT_Length;
2418 // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D;
2419 else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds;
2420 else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume;
2421 else if ( theStr.equals( "Less than" ) ) return FT_LessThan;
2422 else if ( theStr.equals( "More than" ) ) return FT_MoreThan;
2423 else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo;
2424 else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT;
2425 else if ( theStr.equals( "And" ) ) return FT_LogicalAND;
2426 else if ( theStr.equals( "Or" ) ) return FT_LogicalOR;
2427 else if ( theStr.equals( "" ) ) return FT_Undefined;
2428 else return FT_Undefined;
2431 //=======================================================================
2432 // name : toFunctorType
2433 // Purpose : Convert LDOMString to value of ElementType enumeration
2434 //=======================================================================
2435 static inline SMESH::ElementType toElementType( const LDOMString& theStr )
2437 if ( theStr.equals( "NODE" ) ) return SMESH::NODE;
2438 else if ( theStr.equals( "EDGE" ) ) return SMESH::EDGE;
2439 else if ( theStr.equals( "FACE" ) ) return SMESH::FACE;
2440 else if ( theStr.equals( "VOLUME" ) ) return SMESH::VOLUME;
2441 else return SMESH::ALL;
2444 //=======================================================================
2446 // Purpose : Convert ElementType to string
2447 //=======================================================================
2448 static inline LDOMString toString( const SMESH::ElementType theType )
2452 case SMESH::NODE : return "NODE";
2453 case SMESH::EDGE : return "EDGE";
2454 case SMESH::FACE : return "FACE";
2455 case SMESH::VOLUME : return "VOLUME";
2456 case SMESH::ALL : return "ALL";
2457 default : return "";
2461 //=======================================================================
2462 // name : findFilter
2463 // Purpose : Find filter in document
2464 //=======================================================================
2465 static LDOM_Element findFilter( const char* theFilterName,
2466 const LDOM_Document& theDoc,
2467 LDOM_Node* theParent = 0 )
2469 LDOM_Element aRootElement = theDoc.getDocumentElement();
2470 if ( aRootElement.isNull() || !aRootElement.hasChildNodes() )
2471 return LDOM_Element();
2473 for ( LDOM_Node aTypeNode = aRootElement.getFirstChild();
2474 !aTypeNode.isNull(); aTypeNode = aTypeNode.getNextSibling() )
2476 for ( LDOM_Node aFilter = aTypeNode.getFirstChild();
2477 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2479 LDOM_Element* anElem = ( LDOM_Element* )&aFilter;
2480 if ( anElem->getTagName().equals( LDOMString( "filter" ) ) &&
2481 anElem->getAttribute( "name" ).equals( LDOMString( theFilterName ) ) )
2483 if ( theParent != 0 )
2484 *theParent = aTypeNode;
2485 return (LDOM_Element&)aFilter;
2489 return LDOM_Element();
2492 //=======================================================================
2493 // name : getSectionName
2494 // Purpose : Get name of section of filters
2495 //=======================================================================
2496 static const char* getSectionName( const ElementType theType )
2500 case SMESH::NODE : return "Filters for nodes";
2501 case SMESH::EDGE : return "Filters for edges";
2502 case SMESH::FACE : return "Filters for faces";
2503 case SMESH::VOLUME : return "Filters for volumes";
2504 case SMESH::ALL : return "Filters for elements";
2505 default : return "";
2509 //=======================================================================
2510 // name : getSection
2511 // Purpose : Create section for filters corresponding to the entity type
2512 //=======================================================================
2513 static LDOM_Node getSection( const ElementType theType,
2514 LDOM_Document& theDoc,
2515 const bool toCreate = false )
2517 LDOM_Element aRootElement = theDoc.getDocumentElement();
2518 if ( aRootElement.isNull() )
2522 bool anExist = false;
2523 const char* aSectionName = getSectionName( theType );
2524 if ( strcmp( aSectionName, "" ) == 0 )
2527 LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" );
2529 for ( int i = 0, n = aSections.getLength(); i < n; i++ )
2531 aNode = aSections.item( i );
2532 LDOM_Element& anItem = ( LDOM_Element& )aNode;
2533 if ( anItem.getAttribute( "name" ).equals( LDOMString( aSectionName ) ) )
2540 // Create new section if necessary
2545 LDOM_Element aNewItem = theDoc.createElement( "section" );
2546 aNewItem.setAttribute( "name", aSectionName );
2547 aRootElement.appendChild( aNewItem );
2557 //=======================================================================
2558 // name : createFilterItem
2559 // Purpose : Create filter item or LDOM document
2560 //=======================================================================
2561 static LDOM_Element createFilterItem( const char* theName,
2562 SMESH::Filter_ptr theFilter,
2563 LDOM_Document& theDoc )
2565 // create new filter in document
2566 LDOM_Element aFilterItem = theDoc.createElement( "filter" );
2567 aFilterItem.setAttribute( "name", theName );
2569 // save filter criterions
2570 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2572 if ( !theFilter->GetCriteria( aCriteria ) )
2573 return LDOM_Element();
2575 for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ )
2577 LDOM_Element aCriterionItem = theDoc.createElement( "criterion" );
2579 aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) );
2580 aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) );
2581 aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) );
2582 aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) );
2583 aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) );
2585 aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr );
2586 aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) );
2587 aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE ,
2588 toString( (SMESH::ElementType)aCriteria[ i ].TypeOfElement ) );
2590 aFilterItem.appendChild( aCriterionItem );
2596 //=======================================================================
2597 // name : FilterLibrary_i::FilterLibrary_i
2598 // Purpose : Constructor
2599 //=======================================================================
2600 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
2602 myFileName = strdup( theFileName );
2603 SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
2604 myFilterMgr = aFilterMgr->_this();
2608 // Try to use existing library file
2609 bool anExists = false;
2610 if ( !aParser.parse( myFileName ) )
2612 myDoc = aParser.getDocument();
2615 // Create a new XML document if it doesn't exist
2617 myDoc = LDOM_Document::createDocument( LDOMString() );
2619 LDOM_Element aRootElement = myDoc.getDocumentElement();
2620 if ( aRootElement.isNull() )
2622 // If the existing document is empty --> try to create a new one
2624 myDoc = LDOM_Document::createDocument( LDOMString() );
2628 //=======================================================================
2629 // name : FilterLibrary_i::FilterLibrary_i
2630 // Purpose : Constructor
2631 //=======================================================================
2632 FilterLibrary_i::FilterLibrary_i()
2635 SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
2636 myFilterMgr = aFilter->_this();
2638 myDoc = LDOM_Document::createDocument( LDOMString() );
2641 FilterLibrary_i::~FilterLibrary_i()
2644 //TPythonDump()<<this<<".Destroy()";
2647 //=======================================================================
2648 // name : FilterLibrary_i::Copy
2649 // Purpose : Create filter and initialize it with values from library
2650 //=======================================================================
2651 Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
2653 Filter_ptr aRes = Filter::_nil();
2654 LDOM_Node aFilter = findFilter( theFilterName, myDoc );
2656 if ( aFilter.isNull() )
2659 std::list<SMESH::Filter::Criterion> aCriteria;
2661 for ( LDOM_Node aCritNode = aFilter.getFirstChild();
2662 !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() )
2664 LDOM_Element* aCrit = (LDOM_Element*)&aCritNode;
2666 const char* aTypeStr = aCrit->getAttribute( ATTR_TYPE ).GetString();
2667 const char* aCompareStr = aCrit->getAttribute( ATTR_COMPARE ).GetString();
2668 const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString();
2669 const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString();
2670 const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString();
2672 SMESH::Filter::Criterion aCriterion = createCriterion();
2674 aCriterion.Type = toFunctorType( aTypeStr );
2675 aCriterion.Compare = toFunctorType( aCompareStr );
2676 aCriterion.UnaryOp = toFunctorType( aUnaryStr );
2677 aCriterion.BinaryOp = toFunctorType( aBinaryStr );
2679 aCriterion.TypeOfElement = toElementType( anElemTypeStr );
2681 LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD );
2683 aCriterion.Threshold = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2684 ? val : atof( str.GetString() );
2686 str = aCrit->getAttribute( ATTR_TOLERANCE );
2687 aCriterion.Tolerance = str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val )
2688 ? val : atof( str.GetString() );
2690 str = aCrit->getAttribute( ATTR_THRESHOLD_STR );
2691 if ( str.Type() == LDOMBasicString::LDOM_Integer && str.GetInteger( val ) )
2694 sprintf( a, "%d", val );
2695 aCriterion.ThresholdStr = strdup( a );
2698 aCriterion.ThresholdStr = str.GetString();
2700 aCriteria.push_back( aCriterion );
2703 SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria;
2704 aCriteriaVar->length( aCriteria.size() );
2707 std::list<SMESH::Filter::Criterion>::iterator anIter = aCriteria.begin();
2709 for( ; anIter != aCriteria.end(); ++anIter )
2710 aCriteriaVar[ i++ ] = *anIter;
2712 aRes = myFilterMgr->CreateFilter();
2713 aRes->SetCriteria( aCriteriaVar.inout() );
2715 TPythonDump()<<this<<".Copy('"<<theFilterName<<"')";
2720 //=======================================================================
2721 // name : FilterLibrary_i::SetFileName
2722 // Purpose : Set file name for library
2723 //=======================================================================
2724 void FilterLibrary_i::SetFileName( const char* theFileName )
2727 myFileName = strdup( theFileName );
2728 TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
2731 //=======================================================================
2732 // name : FilterLibrary_i::GetFileName
2733 // Purpose : Get file name of library
2734 //=======================================================================
2735 char* FilterLibrary_i::GetFileName()
2737 return CORBA::string_dup( myFileName );
2740 //=======================================================================
2741 // name : FilterLibrary_i::Add
2742 // Purpose : Add new filter to library
2743 //=======================================================================
2744 CORBA::Boolean FilterLibrary_i::Add( const char* theFilterName, Filter_ptr theFilter )
2746 // if filter already in library or entry filter is null do nothing
2747 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2748 if ( !aFilterNode.isNull() || theFilter->_is_nil() )
2751 // get section corresponding to the filter type
2752 ElementType anEntType = theFilter->GetElementType();
2754 LDOM_Node aSection = getSection( anEntType, myDoc, true );
2755 if ( aSection.isNull() )
2758 // create filter item
2759 LDOM_Element aFilterItem = createFilterItem( theFilterName, theFilter, myDoc );
2760 if ( aFilterItem.isNull() )
2764 aSection.appendChild( aFilterItem );
2765 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2766 TPythonDump()<<this<<".Add('"<<theFilterName<<"',"<<aFilter<<")";
2771 //=======================================================================
2772 // name : FilterLibrary_i::Add
2773 // Purpose : Add new filter to library
2774 //=======================================================================
2775 CORBA::Boolean FilterLibrary_i::AddEmpty( const char* theFilterName, ElementType theType )
2777 // if filter already in library or entry filter is null do nothing
2778 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc );
2779 if ( !aFilterNode.isNull() )
2782 LDOM_Node aSection = getSection( theType, myDoc, true );
2783 if ( aSection.isNull() )
2786 // create filter item
2787 Filter_var aFilter = myFilterMgr->CreateFilter();
2789 LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc );
2790 if ( aFilterItem.isNull() )
2794 aSection.appendChild( aFilterItem );
2795 TPythonDump()<<this<<".AddEmpty('"<<theFilterName<<"',"<<theType<<")";
2800 //=======================================================================
2801 // name : FilterLibrary_i::Delete
2802 // Purpose : Delete filter from library
2803 //=======================================================================
2804 CORBA::Boolean FilterLibrary_i::Delete ( const char* theFilterName )
2806 LDOM_Node aParentNode;
2807 LDOM_Node aFilterNode = findFilter( theFilterName, myDoc, &aParentNode );
2808 if ( aFilterNode.isNull() || aParentNode.isNull() )
2811 aParentNode.removeChild( aFilterNode );
2812 TPythonDump()<<this<<".Delete('"<<theFilterName<<"')";
2816 //=======================================================================
2817 // name : FilterLibrary_i::Replace
2818 // Purpose : Replace existing filter with entry filter.
2819 // IMPORTANT : If filter does not exist it is not created
2820 //=======================================================================
2821 CORBA::Boolean FilterLibrary_i::Replace( const char* theFilterName,
2822 const char* theNewName,
2823 Filter_ptr theFilter )
2825 LDOM_Element aFilterItem = findFilter( theFilterName, myDoc );
2826 if ( aFilterItem.isNull() || theFilter->_is_nil() )
2829 LDOM_Element aNewItem = createFilterItem( theNewName, theFilter, myDoc );
2830 if ( aNewItem.isNull() )
2834 aFilterItem.ReplaceElement( aNewItem );
2835 if(Filter_i* aFilter = DownCast<Filter_i*>(theFilter))
2836 TPythonDump()<<this<<".Replace('"<<theFilterName<<"',"<<theNewName<<"',"<<aFilter<<")";
2841 //=======================================================================
2842 // name : FilterLibrary_i::Save
2843 // Purpose : Save library on disk
2844 //=======================================================================
2845 CORBA::Boolean FilterLibrary_i::Save()
2847 if ( myFileName == 0 || strlen( myFileName ) == 0 )
2850 FILE* aOutFile = fopen( myFileName, "wt" );
2854 LDOM_XmlWriter aWriter( aOutFile );
2855 aWriter.SetIndentation( 2 );
2859 TPythonDump()<<this<<".Save()";
2863 //=======================================================================
2864 // name : FilterLibrary_i::SaveAs
2865 // Purpose : Save library on disk
2866 //=======================================================================
2867 CORBA::Boolean FilterLibrary_i::SaveAs( const char* aFileName )
2869 myFileName = strdup ( aFileName );
2870 TPythonDump()<<this<<".SaveAs('"<<aFileName<<"')";
2874 //=======================================================================
2875 // name : FilterLibrary_i::IsPresent
2876 // Purpose : Verify whether filter is in library
2877 //=======================================================================
2878 CORBA::Boolean FilterLibrary_i::IsPresent( const char* theFilterName )
2880 return !findFilter( theFilterName, myDoc ).isNull();
2883 //=======================================================================
2884 // name : FilterLibrary_i::NbFilters
2885 // Purpose : Return amount of filters in library
2886 //=======================================================================
2887 CORBA::Long FilterLibrary_i::NbFilters( ElementType theType )
2889 string_array_var aNames = GetNames( theType );
2890 return aNames->length();
2893 //=======================================================================
2894 // name : FilterLibrary_i::GetNames
2895 // Purpose : Get names of filters from library
2896 //=======================================================================
2897 string_array* FilterLibrary_i::GetNames( ElementType theType )
2899 string_array_var anArray = new string_array;
2900 TColStd_SequenceOfHAsciiString aSeq;
2902 LDOM_Node aSection = getSection( theType, myDoc, false );
2904 if ( !aSection.isNull() )
2906 for ( LDOM_Node aFilter = aSection.getFirstChild();
2907 !aFilter.isNull(); aFilter = aFilter.getNextSibling() )
2909 LDOM_Element& anElem = ( LDOM_Element& )aFilter;
2910 aSeq.Append( new TCollection_HAsciiString(
2911 (Standard_CString)anElem.getAttribute( "name" ).GetString() ) );
2915 anArray->length( aSeq.Length() );
2916 for ( int i = 1, n = aSeq.Length(); i <= n; i++ )
2917 anArray[ i - 1 ] = CORBA::string_dup( aSeq( i )->ToCString() );
2919 return anArray._retn();
2922 //=======================================================================
2923 // name : FilterLibrary_i::GetAllNames
2924 // Purpose : Get names of filters from library
2925 //=======================================================================
2926 string_array* FilterLibrary_i::GetAllNames()
2928 string_array_var aResArray = new string_array;
2929 for ( int type = SMESH::ALL; type <= SMESH::VOLUME; type++ )
2931 SMESH::string_array_var aNames = GetNames( (SMESH::ElementType)type );
2933 int aPrevLength = aResArray->length();
2934 aResArray->length( aPrevLength + aNames->length() );
2935 for ( int i = 0, n = aNames->length(); i < n; i++ )
2936 aResArray[ aPrevLength + i ] = aNames[ i ];
2939 return aResArray._retn();