X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_Filter_i.cxx;h=91a858a622e70e5ff81b977239f9917b0ad3aee3;hp=a5c073f29dd364497cbebc5192633d2e001f88f7;hb=6bac08c1a81f34d3f21c550bd92f83654b2546a5;hpb=090aff07266d376ae028ae43434bdea7c0a0f9bb diff --git a/src/SMESH_I/SMESH_Filter_i.cxx b/src/SMESH_I/SMESH_Filter_i.cxx index a5c073f29..91a858a62 100644 --- a/src/SMESH_I/SMESH_Filter_i.cxx +++ b/src/SMESH_I/SMESH_Filter_i.cxx @@ -1,326 +1,92 @@ -// SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. // +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses // File : SMESH_Filter_i.cxx // Author : Alexey Petrov, OCC // Module : SMESH - #include "SMESH_Filter_i.hxx" -#include "SMESH_Gen_i.hxx" - +#include "SMDS_ElemIterator.hxx" #include "SMDS_Mesh.hxx" -#include "SMDS_MeshNode.hxx" #include "SMDS_MeshElement.hxx" - +#include "SMDS_MeshNode.hxx" #include "SMESHDS_Mesh.hxx" +#include "SMESH_Gen_i.hxx" +#include "SMESH_Group_i.hxx" +#include "SMESH_PythonDump.hxx" +#include +#include + +#include +#include +#include +#include +#include #include #include #include -#include -#include #include -#include +#include #include +#include #include #include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include -#include -#include +#include +#include using namespace SMESH; using namespace SMESH::Controls; -/* - Class : BelongToGeom - Description : Predicate for verifying whether entiy belong to - specified geometrical support -*/ - -Controls::BelongToGeom::BelongToGeom() -: myMeshDS(NULL), - myType(SMDSAbs_All) -{} - -void Controls::BelongToGeom::SetMesh( SMDS_Mesh* theMesh ) -{ - myMeshDS = dynamic_cast(theMesh); -} - -void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape ) -{ - myShape = theShape; -} - -static bool IsContains( SMESHDS_Mesh* theMeshDS, - const TopoDS_Shape& theShape, - const SMDS_MeshElement* theElem, - TopAbs_ShapeEnum theFindShapeEnum, - TopAbs_ShapeEnum theAvoidShapeEnum = TopAbs_SHAPE ) -{ - TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum ); - - while( anExp.More() ) - { - const TopoDS_Shape& aShape = anExp.Current(); - if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){ - if( aSubMesh->Contains( theElem ) ) - return true; - } - anExp.Next(); - } - return false; -} - -bool Controls::BelongToGeom::IsSatisfy( long theId ) -{ - if ( myMeshDS == 0 || myShape.IsNull() ) - return false; - - if( myType == SMDSAbs_Node ) - { - if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) ) - { - const SMDS_PositionPtr& aPosition = aNode->GetPosition(); - SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition(); - switch( aTypeOfPosition ) - { - case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX ); - case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE ); - case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE ); - case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL ); - } - } - } - else - { - if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) ) - { - if( myType == SMDSAbs_All ) - { - return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) || - IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) || - IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )|| - IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID ); - } - else if( myType == anElem->GetType() ) - { - switch( myType ) - { - case SMDSAbs_Edge : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ); - case SMDSAbs_Face : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ); - case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )|| - IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID ); - } - } - } - } - - return false; -} - -void Controls::BelongToGeom::SetType( SMDSAbs_ElementType theType ) -{ - myType = theType; -} - -SMDSAbs_ElementType Controls::BelongToGeom::GetType() const -{ - return myType; -} - -TopoDS_Shape Controls::BelongToGeom::GetShape() -{ - return myShape; -} - -SMESHDS_Mesh* Controls::BelongToGeom::GetMeshDS() -{ - return myMeshDS; -} - -/* - Class : LyingOnGeom - Description : Predicate for verifying whether entiy lying or partially lying on - specified geometrical support -*/ - -Controls::LyingOnGeom::LyingOnGeom() -: myMeshDS(NULL), - myType(SMDSAbs_All) -{} - -void Controls::LyingOnGeom::SetMesh( SMDS_Mesh* theMesh ) -{ - myMeshDS = dynamic_cast(theMesh); -} - -void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape ) -{ - myShape = theShape; -} - -bool Controls::LyingOnGeom::IsSatisfy( long theId ) -{ - if ( myMeshDS == 0 || myShape.IsNull() ) - return false; - - if( myType == SMDSAbs_Node ) - { - if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) ) - { - const SMDS_PositionPtr& aPosition = aNode->GetPosition(); - SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition(); - switch( aTypeOfPosition ) - { - case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX ); - case SMDS_TOP_EDGE : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE ); - case SMDS_TOP_FACE : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE ); - case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL ); - } - } - } - else - { - if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) ) - { - if( myType == SMDSAbs_All ) - { - return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) || - Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) || - Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )|| - Contains( myMeshDS,myShape,anElem,TopAbs_SOLID ); - } - else if( myType == anElem->GetType() ) - { - switch( myType ) - { - case SMDSAbs_Edge : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ); - case SMDSAbs_Face : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE ); - case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )|| - Contains( myMeshDS,myShape,anElem,TopAbs_SOLID ); - } - } - } - } - - return false; -} - -void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType ) -{ - myType = theType; -} - -SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const -{ - return myType; -} - -TopoDS_Shape Controls::LyingOnGeom::GetShape() -{ - return myShape; -} - -SMESHDS_Mesh* Controls::LyingOnGeom::GetMeshDS() -{ - return myMeshDS; -} -bool Controls::LyingOnGeom::Contains( SMESHDS_Mesh* theMeshDS, - const TopoDS_Shape& theShape, - const SMDS_MeshElement* theElem, - TopAbs_ShapeEnum theFindShapeEnum, - TopAbs_ShapeEnum theAvoidShapeEnum ) +namespace SMESH { - if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum)) - return true; - - if ( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( theShape ) ) - { - SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes(); - while ( aNodeIt->more() ) - { - const SMDS_MeshNode* aNode = static_cast(aNodeIt->next()); - SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator(); - while ( anElemIt->more() ) - { - const SMDS_MeshElement* anElement = static_cast(anElemIt->next()); - if (anElement == theElem) - return true; - } - } - } - - TopExp_Explorer anExp( theShape,TopAbs_VERTEX,theAvoidShapeEnum ); - - while( anExp.More() ) + Predicate_i* + GetPredicate( Predicate_ptr thePredicate ) { - const TopoDS_Shape& aShape = anExp.Current(); - if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){ - SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes(); - while ( aNodeIt->more() ) - { - const SMDS_MeshNode* aNode = static_cast(aNodeIt->next()); - SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator(); - while ( anElemIt->more() ) - { - const SMDS_MeshElement* anElement = static_cast(anElemIt->next()); - if (anElement == theElem) - return true; - } - } - } - anExp.Next(); + return DownCast(thePredicate); } - return false; } - /* AUXILIARY METHODS */ -static inline SMDS_Mesh* MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh ) +inline +const SMDS_Mesh* +MeshPtr2SMDSMesh( SMESH_Mesh_ptr theMesh ) { - SMESH_Mesh_i* anImplPtr = - dynamic_cast( SMESH_Gen_i::GetServant( theMesh ).in() ); + SMESH_Mesh_i* anImplPtr = DownCast(theMesh); return anImplPtr ? anImplPtr->GetImpl().GetMeshDS() : 0; } -static inline SMESH::long_array* toArray( const TColStd_ListOfInteger& aList ) +inline +SMESH::long_array* +toArray( const TColStd_ListOfInteger& aList ) { SMESH::long_array_var anArray = new SMESH::long_array; anArray->length( aList.Extent() ); @@ -332,7 +98,9 @@ static inline SMESH::long_array* toArray( const TColStd_ListOfInteger& aList ) return anArray._retn(); } -static inline SMESH::double_array* toArray( const TColStd_ListOfReal& aList ) +inline +SMESH::double_array* +toArray( const TColStd_ListOfReal& aList ) { SMESH::double_array_var anArray = new SMESH::double_array; anArray->length( aList.Extent() ); @@ -354,6 +122,7 @@ static SMESH::Filter::Criterion createCriterion() aCriterion.UnaryOp = FT_Undefined; aCriterion.BinaryOp = FT_Undefined; aCriterion.ThresholdStr = ""; + aCriterion.ThresholdID = ""; aCriterion.Tolerance = Precision::Confusion(); aCriterion.TypeOfElement = SMESH::ALL; aCriterion.Precision = -1; @@ -365,28 +134,56 @@ static TopoDS_Shape getShapeByName( const char* theName ) { if ( theName != 0 ) { - SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); - SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy(); - if ( aStudy != 0 ) + SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); + SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy(); + if ( !aStudy->_is_nil() ) { - SALOMEDS::Study::ListOfSObject_var aList = - aStudy->FindObjectByName( theName, "GEOM" ); + SALOMEDS::Study::ListOfSObject_var aList = aStudy->FindObjectByName( theName, "GEOM" ); if ( aList->length() > 0 ) { - GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() ); - if ( !aGeomObj->_is_nil() ) - { - GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine(); - TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, aGeomObj ); - return aLocShape; - } + CORBA::Object_var anObj = aList[ 0 ]->GetObject(); + GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( anObj ); + TopoDS_Shape shape = aSMESHGen->GeomObjectToShape( aGeomObj ); + SALOME::UnRegister( aList ); // UnRegister() objects in aList + return shape; } } } return TopoDS_Shape(); } +static TopoDS_Shape getShapeByID (const char* theID) +{ + if ( theID && strlen( theID ) > 0 ) { + SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); + SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy(); + if ( !aStudy->_is_nil() ) { + SALOMEDS::SObject_wrap aSObj = aStudy->FindObjectID(theID); + if ( !aSObj->_is_nil() ) { + CORBA::Object_var obj = aSObj->GetObject(); + GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj); + return aSMESHGen->GeomObjectToShape( aGeomObj ); + } + } + } + return TopoDS_Shape(); +} +static std::string getShapeNameByID (const char* theID) +{ + if ( theID && strlen( theID ) > 0 ) { + SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); + SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy(); + if ( !aStudy->_is_nil() ) { + SALOMEDS::SObject_wrap aSObj = aStudy->FindObjectID(theID); + if ( !aSObj->_is_nil() ) { + CORBA::String_var name = aSObj->GetName(); + return name.in(); + } + } + } + return ""; +} /* FUNCTORS @@ -394,18 +191,25 @@ static TopoDS_Shape getShapeByName( const char* theName ) /* Class : Functor_i - Description : An abstact class for all functors + Description : An abstact class for all functors */ -Functor_i::Functor_i(): +Functor_i::Functor_i(): SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() ) { - SMESH_Gen_i::GetPOA()->activate_object( this ); + //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method + //PortableServer::ObjectId_var anObjectId = + // SMESH_Gen_i::GetPOA()->activate_object( this ); +} + +Functor_i::~Functor_i() +{ + //TPythonDump()<SetMesh( MeshPtr2SMDSMesh( theMesh ) ); - INFOS("Functor_i::SetMesh~"); + TPythonDump()<GetValue( theId ); } +SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals, CORBA::Boolean isLogarithmic) +{ + std::vector nbEvents; + std::vector funValues; + std::vector elements; + myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements,0,isLogarithmic); + + SMESH::Histogram_var histogram = new SMESH::Histogram; + + nbIntervals = CORBA::Short( Min( int( nbEvents.size()), + int( funValues.size() - 1 ))); + if ( nbIntervals > 0 ) + { + histogram->length( nbIntervals ); + for ( int i = 0; i < nbIntervals; ++i ) + { + HistogramRectangle& rect = histogram[i]; + rect.nbEvents = nbEvents[i]; + rect.min = funValues[i]; + rect.max = funValues[i+1]; + } + } + return histogram._retn(); +} + +SMESH::Histogram* NumericalFunctor_i::GetLocalHistogram(CORBA::Short nbIntervals, + CORBA::Boolean isLogarithmic, + SMESH::SMESH_IDSource_ptr object) +{ + SMESH::Histogram_var histogram = new SMESH::Histogram; + + std::vector nbEvents; + std::vector funValues; + std::vector elements; + + SMDS_ElemIteratorPtr elemIt; + if ( SMESH::DownCast< SMESH_GroupOnFilter_i* >( object ) || + SMESH::DownCast< SMESH::Filter_i* >( object )) + { + elemIt = SMESH_Mesh_i::GetElements( object, GetElementType() ); + if ( !elemIt ) return histogram._retn(); + } + else + { + SMESH::SMESH_Mesh_var mesh = object->GetMesh(); + SMESH::long_array_var objNbElems = object->GetNbElementsByType(); + SMESH::long_array_var meshNbElems = mesh-> GetNbElementsByType(); + if ( meshNbElems[ GetElementType() ] != + objNbElems [ GetElementType() ] ) + { + elements.reserve( objNbElems[ GetElementType() ]); + elemIt = SMESH_Mesh_i::GetElements( object, GetElementType() ); + } + } + if ( elemIt ) + { + while ( elemIt->more() ) + elements.push_back( elemIt->next()->GetID() ); + if ( elements.empty() ) return histogram._retn(); + } + + myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements,0,isLogarithmic); + + nbIntervals = CORBA::Short( Min( int( nbEvents.size()), + int( funValues.size() - 1 ))); + if ( nbIntervals > 0 ) + { + histogram->length( nbIntervals ); + for ( int i = 0; i < nbIntervals; ++i ) + { + HistogramRectangle& rect = histogram[i]; + rect.nbEvents = nbEvents[i]; + rect.min = funValues[i]; + rect.max = funValues[i+1]; + } + } + return histogram._retn(); +} + void NumericalFunctor_i::SetPrecision( CORBA::Long thePrecision ) { myNumericalFunctorPtr->SetPrecision( thePrecision ); + TPythonDump()<GetValues( aValues ); - + (dynamic_cast(myFunctorPtr.get()))->GetValues( aValues ); + long i = 0, iEnd = aValues.size(); SMESH::Length2D::Values_var aResult = new SMESH::Length2D::Values(iEnd); + aResult->length(iEnd); SMESH::Controls::Length2D::TValues::const_iterator anIter; for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ ) { const SMESH::Controls::Length2D::Value& aVal = *anIter; SMESH::Length2D::Value &aValue = aResult[ i ]; - + aValue.myLength = aVal.myLength; aValue.myPnt1 = aVal.myPntId[ 0 ]; aValue.myPnt2 = aVal.myPntId[ 1 ]; - } INFOS("Length2D_i::GetValuess~"); @@ -620,6 +548,21 @@ FunctorType MultiConnection_i::GetFunctorType() return SMESH::FT_MultiConnection; } +/* + Class : BallDiameter_i + Description : Functor returning diameter of a ball element +*/ +BallDiameter_i::BallDiameter_i() +{ + myNumericalFunctorPtr.reset( new Controls::BallDiameter() ); + myFunctorPtr = myNumericalFunctorPtr; +} + +FunctorType BallDiameter_i::GetFunctorType() +{ + return SMESH::FT_BallDiameter; +} + /* Class : MultiConnection2D_i Description : Functor for calculating number of faces conneted to the edge @@ -639,22 +582,22 @@ SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues() { INFOS("MultiConnection2D_i::GetValues"); SMESH::Controls::MultiConnection2D::MValues aValues; - myMulticonnection2DPtr->GetValues( aValues ); + (dynamic_cast(myFunctorPtr.get()))->GetValues( aValues ); long i = 0, iEnd = aValues.size(); SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd); + aResult->length(iEnd); SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter; for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ ) { const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first; SMESH::MultiConnection2D::Value &aValue = aResult[ i ]; - + aValue.myPnt1 = aVal.myPntId[ 0 ]; aValue.myPnt2 = aVal.myPntId[ 1 ]; aValue.myNbConnects = (*anIter).second; - } INFOS("Multiconnection2D_i::GetValuess~"); @@ -675,45 +618,147 @@ CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId ) return myPredicatePtr->IsSatisfy( theId ); } +CORBA::Long Predicate_i::NbSatisfying( SMESH::SMESH_IDSource_ptr obj ) +{ + SMESH::SMESH_Mesh_var meshVar = obj->GetMesh(); + const SMDS_Mesh* meshDS = MeshPtr2SMDSMesh( meshVar ); + if ( !meshDS ) + return 0; + myPredicatePtr->SetMesh( meshDS ); + + SMDSAbs_ElementType elemType = SMDSAbs_ElementType( GetElementType() ); + + int nb = 0; + SMDS_ElemIteratorPtr elemIt = + SMESH::DownCast( meshVar )->GetElements( obj, GetElementType() ); + if ( elemIt ) + while ( elemIt->more() ) + { + const SMDS_MeshElement* e = elemIt->next(); + if ( e && e->GetType() == elemType ) + nb += myPredicatePtr->IsSatisfy( e->GetID() ); + } + return nb; +} + Controls::PredicatePtr Predicate_i::GetPredicate() { return myPredicatePtr; } - /* - Class : BelongToGeom_i - Description : Predicate for selection on geometrical support + Class : BadOrientedVolume_i + Description : Verify whether a mesh volume is incorrectly oriented from + the point of view of MED convention */ -BelongToGeom_i::BelongToGeom_i() +BadOrientedVolume_i::BadOrientedVolume_i() { - myBelongToGeomPtr.reset( new Controls::BelongToGeom() ); - myFunctorPtr = myPredicatePtr = myBelongToGeomPtr; - myShapeName = 0; -} + Controls::PredicatePtr control( new Controls::BadOrientedVolume() ); + myFunctorPtr = myPredicatePtr = control; +}; -BelongToGeom_i::~BelongToGeom_i() +FunctorType BadOrientedVolume_i::GetFunctorType() { - delete myShapeName; + return SMESH::FT_BadOrientedVolume; } -void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom ) +/* + Class : BareBorderVolume_i + Description : Verify whether a mesh volume has a free facet without a face on it +*/ +BareBorderVolume_i::BareBorderVolume_i() { - if ( theGeom->_is_nil() ) - return; - SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); - GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine(); - TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom ); - myBelongToGeomPtr->SetGeom( aLocShape ); -} + Controls::PredicatePtr control( new Controls::BareBorderVolume() ); + myFunctorPtr = myPredicatePtr = control; +}; -void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape ) +FunctorType BareBorderVolume_i::GetFunctorType() { - myBelongToGeomPtr->SetGeom( theShape ); + return SMESH::FT_BareBorderVolume; } -void BelongToGeom_i::SetElementType(ElementType theType){ +/* + Class : BareBorderFace_i + Description : Verify whether a mesh face has a free border without an edge on it +*/ +BareBorderFace_i::BareBorderFace_i() +{ + Controls::PredicatePtr control( new Controls::BareBorderFace() ); + myFunctorPtr = myPredicatePtr = control; +}; + +FunctorType BareBorderFace_i::GetFunctorType() +{ + return SMESH::FT_BareBorderFace; +} + +/* + Class : OverConstrainedVolume_i + Description : Verify whether a mesh volume has only one facet shared with other volumes +*/ +OverConstrainedVolume_i::OverConstrainedVolume_i() +{ + Controls::PredicatePtr control( new Controls::OverConstrainedVolume() ); + myFunctorPtr = myPredicatePtr = control; +}; + +FunctorType OverConstrainedVolume_i::GetFunctorType() +{ + return SMESH::FT_OverConstrainedVolume; +} + +/* + Class : OverConstrainedFace_i + Description : Verify whether a mesh face has only one border shared with other faces +*/ +OverConstrainedFace_i::OverConstrainedFace_i() +{ + Controls::PredicatePtr control( new Controls::OverConstrainedFace() ); + myFunctorPtr = myPredicatePtr = control; +}; + +FunctorType OverConstrainedFace_i::GetFunctorType() +{ + return SMESH::FT_OverConstrainedFace; +} + +/* + Class : BelongToGeom_i + Description : Predicate for selection on geometrical support +*/ +BelongToGeom_i::BelongToGeom_i() +{ + myBelongToGeomPtr.reset( new Controls::BelongToGeom() ); + myFunctorPtr = myPredicatePtr = myBelongToGeomPtr; + myShapeName = 0; + myShapeID = 0; +} + +BelongToGeom_i::~BelongToGeom_i() +{ + delete myShapeName; + delete myShapeID; +} + +void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom ) +{ + if ( theGeom->_is_nil() ) + return; + SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); + GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine(); + TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom ); + myBelongToGeomPtr->SetGeom( aLocShape ); + TPythonDump()<SetGeom( theShape ); +} + +void BelongToGeom_i::SetElementType(ElementType theType){ myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType)); + TPythonDump()<SetGeom( getShapeByName( myShapeName ) ); + TPythonDump()<SetGeom( getShapeByID(myShapeID) ); + else + myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) ); } char* BelongToGeom_i::GetShapeName() @@ -733,6 +795,22 @@ char* BelongToGeom_i::GetShapeName() return CORBA::string_dup( myShapeName ); } +char* BelongToGeom_i::GetShapeID() +{ + return CORBA::string_dup( myShapeID ); +} + +void BelongToGeom_i::SetTolerance( CORBA::Double theToler ) +{ + myBelongToGeomPtr->SetTolerance( theToler ); + TPythonDump()<GetTolerance(); +} + /* Class : BelongToSurface_i Description : Predicate for selection on geometrical support @@ -742,12 +820,14 @@ BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceTyp myElementsOnSurfacePtr.reset( new Controls::ElementsOnSurface() ); myFunctorPtr = myPredicatePtr = myElementsOnSurfacePtr; myShapeName = 0; + myShapeID = 0; mySurfaceType = theSurfaceType; } BelongToSurface_i::~BelongToSurface_i() { delete myShapeName; + delete myShapeID; } void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType ) @@ -755,7 +835,7 @@ void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType t if ( theGeom->_is_nil() ) return; SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); - GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine(); + GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine(); TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom ); if ( aLocShape.ShapeType() == TopAbs_FACE ) @@ -776,6 +856,23 @@ void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType ) delete myShapeName; myShapeName = strdup( theName ); myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType ); + TPythonDump()<SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType ); + else + myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType ); } char* BelongToSurface_i::GetShapeName() @@ -783,9 +880,15 @@ char* BelongToSurface_i::GetShapeName() return CORBA::string_dup( myShapeName ); } +char* BelongToSurface_i::GetShapeID() +{ + return CORBA::string_dup( myShapeID ); +} + void BelongToSurface_i::SetTolerance( CORBA::Double theToler ) { myElementsOnSurfacePtr->SetTolerance( theToler ); + TPythonDump()<GetTolerance(); } +void BelongToSurface_i::SetUseBoundaries( CORBA::Boolean theUseBndRestrictions ) +{ + myElementsOnSurfacePtr->SetUseBoundaries( theUseBndRestrictions ); + TPythonDump()<GetUseBoundaries(); +} + + /* Class : BelongToPlane_i Description : Verify whether mesh element lie in pointed Geom planar object @@ -806,6 +921,7 @@ BelongToPlane_i::BelongToPlane_i() void BelongToPlane_i::SetPlane( GEOM::GEOM_Object_ptr theGeom, ElementType theType ) { BelongToSurface_i::SetSurface( theGeom, theType ); + TPythonDump()<_is_nil() ) + return; + TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom ); + if ( !aLocShape.IsNull() && aLocShape.ShapeType() != TopAbs_FACE ) + aLocShape.Nullify(); + + BelongToSurface_i::myElementsOnSurfacePtr->SetSurface( aLocShape, (SMDSAbs_ElementType)theType ); + TPythonDump()<_is_nil() ) return; SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); - GEOM::GEOM_Gen_var aGEOMGen = SMESH_Gen_i::GetGeomEngine(); + GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine(); TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom ); myLyingOnGeomPtr->SetGeom( aLocShape ); + TPythonDump()<SetType(SMDSAbs_ElementType(theType)); + TPythonDump()<SetGeom( getShapeByName( myShapeName ) ); + TPythonDump()<SetGeom( getShapeByID(myShapeID) ); + else + myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) ); } char* LyingOnGeom_i::GetShapeName() @@ -885,6 +1050,22 @@ char* LyingOnGeom_i::GetShapeName() return CORBA::string_dup( myShapeName ); } +char* LyingOnGeom_i::GetShapeID() +{ + return CORBA::string_dup( myShapeID ); +} + +void LyingOnGeom_i::SetTolerance( CORBA::Double theToler ) +{ + myLyingOnGeomPtr->SetTolerance( theToler ); + TPythonDump()<GetTolerance(); +} + /* Class : FreeBorders_i Description : Predicate for free borders @@ -915,17 +1096,18 @@ SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders() INFOS("FreeEdges_i::GetBorders"); SMESH::Controls::FreeEdges::TBorders aBorders; myFreeEdgesPtr->GetBoreders( aBorders ); - + long i = 0, iEnd = aBorders.size(); - SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders(iEnd); + SMESH::FreeEdges::Borders_var aResult = new SMESH::FreeEdges::Borders; + aResult->length(iEnd); SMESH::Controls::FreeEdges::TBorders::const_iterator anIter; for ( anIter = aBorders.begin() ; anIter != aBorders.end(); anIter++, i++ ) { const SMESH::Controls::FreeEdges::Border& aBord = *anIter; SMESH::FreeEdges::Border &aBorder = aResult[ i ]; - + aBorder.myElemId = aBord.myElemId; aBorder.myPnt1 = aBord.myPntId[ 0 ]; aBorder.myPnt2 = aBord.myPntId[ 1 ]; @@ -940,6 +1122,107 @@ FunctorType FreeEdges_i::GetFunctorType() return SMESH::FT_FreeEdges; } +/* + Class : FreeFaces_i + Description : Predicate for free faces +*/ +FreeFaces_i::FreeFaces_i() +{ + myPredicatePtr.reset(new Controls::FreeFaces()); + myFunctorPtr = myPredicatePtr; +} + +FunctorType FreeFaces_i::GetFunctorType() +{ + return SMESH::FT_FreeFaces; +} + +/* + Class : FreeNodes_i + Description : Predicate for free nodes +*/ +FreeNodes_i::FreeNodes_i() +{ + myPredicatePtr.reset(new Controls::FreeNodes()); + myFunctorPtr = myPredicatePtr; +} + +FunctorType FreeNodes_i::GetFunctorType() +{ + return SMESH::FT_FreeNodes; +} + +/* + Class : EqualNodes_i + Description : Predicate for Equal nodes +*/ +EqualNodes_i::EqualNodes_i() +{ + myCoincidentNodesPtr.reset(new Controls::CoincidentNodes()); + myFunctorPtr = myPredicatePtr = myCoincidentNodesPtr; +} + +FunctorType EqualNodes_i::GetFunctorType() +{ + return SMESH::FT_EqualNodes; +} + +void EqualNodes_i::SetTolerance( double tol ) +{ + myCoincidentNodesPtr->SetTolerance( tol ); +} + +double EqualNodes_i::GetTolerance() +{ + return myCoincidentNodesPtr->GetTolerance(); +} + +/* + Class : EqualEdges_i + Description : Predicate for Equal Edges +*/ +EqualEdges_i::EqualEdges_i() +{ + myPredicatePtr.reset(new Controls::CoincidentElements1D()); + myFunctorPtr = myPredicatePtr; +} + +FunctorType EqualEdges_i::GetFunctorType() +{ + return SMESH::FT_EqualEdges; +} + +/* + Class : EqualFaces_i + Description : Predicate for Equal Faces +*/ +EqualFaces_i::EqualFaces_i() +{ + myPredicatePtr.reset(new Controls::CoincidentElements2D()); + myFunctorPtr = myPredicatePtr; +} + +FunctorType EqualFaces_i::GetFunctorType() +{ + return SMESH::FT_EqualFaces; +} + +/* + Class : EqualVolumes_i + Description : Predicate for Equal Volumes +*/ +EqualVolumes_i::EqualVolumes_i() +{ + myPredicatePtr.reset(new Controls::CoincidentElements3D()); + myFunctorPtr = myPredicatePtr; +} + +FunctorType EqualVolumes_i::GetFunctorType() +{ + return SMESH::FT_EqualVolumes; +} + + /* Class : RangeOfIds_i Description : Predicate for Range of Ids. @@ -960,29 +1243,360 @@ void RangeOfIds_i::SetRange( const SMESH::long_array& theIds ) CORBA::Long iEnd = theIds.length(); for ( CORBA::Long i = 0; i < iEnd; i++ ) myRangeOfIdsPtr->AddToRange( theIds[ i ] ); + TPythonDump()<SetRangeStr( + TCollection_AsciiString( (Standard_CString)theRange ) ); +} + +char* RangeOfIds_i::GetRangeStr() +{ + TCollection_AsciiString aStr; + myRangeOfIdsPtr->GetRangeStr( aStr ); + return CORBA::string_dup( aStr.ToCString() ); +} + +void RangeOfIds_i::SetElementType( ElementType theType ) +{ + myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) ); + TPythonDump()<SetType(SMDSAbs_ElementType(theType)); + TPythonDump()<SetColorStr( + TCollection_AsciiString( (Standard_CString)theColor ) ); + TPythonDump()<GetColorStr( aStr ); + return CORBA::string_dup( aStr.ToCString() ); +} + +void GroupColor_i::SetElementType(ElementType theType) +{ + myGroupColorPtr->SetType(SMDSAbs_ElementType(theType)); + TPythonDump()<SetType(SMDSAbs_ElementType(theType)); + TPythonDump()<SetGeomType(SMDSAbs_GeometryType(theType)); + TPythonDump()<GetGeomType(); +} + +FunctorType ElemGeomType_i::GetFunctorType() +{ + return SMESH::FT_ElemGeomType; +} + +/* + Class : ElemEntityType_i + Description : Predicate check is element has indicated entity type +*/ +ElemEntityType_i::ElemEntityType_i() +{ + myElemEntityTypePtr.reset(new Controls::ElemEntityType()); + myFunctorPtr = myPredicatePtr = myElemEntityTypePtr; +} + +void ElemEntityType_i::SetElementType(ElementType theType) +{ + myElemEntityTypePtr->SetType(SMDSAbs_ElementType(theType)); + TPythonDump()<SetElemEntityType(SMDSAbs_EntityType (theEntityType)); + TPythonDump()<GetElemEntityType(); +} + +FunctorType ElemEntityType_i::GetFunctorType() +{ + return SMESH::FT_EntityType; +} + +/* + Class : CoplanarFaces_i + Description : Returns true if a mesh face is a coplanar neighbour to a given one +*/ +CoplanarFaces_i::CoplanarFaces_i() +{ + myCoplanarFacesPtr.reset(new Controls::CoplanarFaces()); + myFunctorPtr = myPredicatePtr = myCoplanarFacesPtr; +} + +void CoplanarFaces_i::SetFace ( CORBA::Long theFaceID ) +{ + myCoplanarFacesPtr->SetFace(theFaceID); + TPythonDump()<SetTolerance(theToler); + TPythonDump()<GetFace(); +} + +char* CoplanarFaces_i::GetFaceAsString () const +{ + TCollection_AsciiString str(Standard_Integer(myCoplanarFacesPtr->GetFace())); + return CORBA::string_dup( str.ToCString() ); +} + +CORBA::Double CoplanarFaces_i::GetTolerance() const +{ + return myCoplanarFacesPtr->GetTolerance(); +} + +FunctorType CoplanarFaces_i::GetFunctorType() +{ + return SMESH::FT_CoplanarFaces; +} + +/* + * Class : ConnectedElements_i + * Description : Returns true if an element is connected via other elements to the element + * located at a given point. + */ +ConnectedElements_i::ConnectedElements_i() +{ + myConnectedElementsPtr.reset(new Controls::ConnectedElements()); + myFunctorPtr = myPredicatePtr = myConnectedElementsPtr; +} + +FunctorType ConnectedElements_i::GetFunctorType() +{ + return FT_ConnectedElements; +} + +void ConnectedElements_i::SetElementType( ElementType theType ) +{ + myConnectedElementsPtr->SetType( SMDSAbs_ElementType( theType )); + TPythonDump() << this << ".SetElementType( " << theType << " )"; } -CORBA::Boolean RangeOfIds_i::SetRangeStr( const char* theRange ) +void ConnectedElements_i::SetPoint( CORBA::Double x, CORBA::Double y, CORBA::Double z ) { - return myRangeOfIdsPtr->SetRangeStr( - TCollection_AsciiString( (Standard_CString)theRange ) ); + myConnectedElementsPtr->SetPoint( x,y,z ); + myVertexID.clear(); + TPythonDump() << this << ".SetPoint( " << x << ", " << y << ", " << z << " )"; } -char* RangeOfIds_i::GetRangeStr() +void ConnectedElements_i::SetVertex( GEOM::GEOM_Object_ptr vertex ) + throw (SALOME::SALOME_Exception) { - TCollection_AsciiString aStr; - myRangeOfIdsPtr->GetRangeStr( aStr ); - return CORBA::string_dup( aStr.ToCString() ); + TopoDS_Shape shape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( vertex ); + if ( shape.IsNull() ) + THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetVertex(): NULL Vertex", + SALOME::BAD_PARAM ); + + TopExp_Explorer v( shape, TopAbs_VERTEX ); + if ( !v.More() ) + THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetVertex(): empty vertex", + SALOME::BAD_PARAM ); + + gp_Pnt p = BRep_Tool::Pnt( TopoDS::Vertex( v.Current() )); + myConnectedElementsPtr->SetPoint( p.X(), p.Y(), p.Z() ); + // + CORBA::String_var id = vertex->GetStudyEntry(); + myVertexID = id.in(); + + TPythonDump() << this << ".SetVertex( " << vertex << " )"; } -void RangeOfIds_i::SetElementType( ElementType theType ) +void ConnectedElements_i::SetNode ( CORBA::Long nodeID ) + throw (SALOME::SALOME_Exception) { - myRangeOfIdsPtr->SetType( SMDSAbs_ElementType( theType ) ); + if ( nodeID < 1 ) + THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetNode(): nodeID must be > 0", + SALOME::BAD_PARAM ); + + myConnectedElementsPtr->SetNode( nodeID ); + myVertexID.clear(); + TPythonDump() << this << ".SetNode( " << nodeID << " )"; } -FunctorType RangeOfIds_i::GetFunctorType() +/*! + * \brief This is a comfort method for Filter dialog + */ +void ConnectedElements_i::SetThreshold ( const char* threshold, + SMESH::ConnectedElements::ThresholdType type ) + throw (SALOME::SALOME_Exception) +{ + if ( !threshold ) + THROW_SALOME_CORBA_EXCEPTION( "ConnectedElements_i::SetThreshold(): NULL threshold", + SALOME::BAD_PARAM ); + switch ( type ) + { + case SMESH::ConnectedElements::POINT: // read 3 node coordinates /////////////////// + { + vector< double > xyz; + char* endptr; + do + { + // skip a separator + while ( *threshold && + *threshold != '+' && + *threshold != '-' && + !isdigit( *threshold )) + ++threshold; + if ( !*threshold ) + break; + // read a coordinate + xyz.push_back( strtod( threshold, &endptr )); + if ( threshold == endptr ) + { + xyz.resize( xyz.size() - 1 ); + break; + } + threshold = endptr; + } + while ( xyz.size() < 3 ); + + if ( xyz.size() < 3 ) + THROW_SALOME_CORBA_EXCEPTION + ( "ConnectedElements_i::SetThreshold(): invalid point coordinates", SALOME::BAD_PARAM ); + + SetPoint( xyz[0], xyz[1], xyz[2] ); + break; + } + case SMESH::ConnectedElements::VERTEX: // get a VERTEX by its entry ///////////////// + { + SALOMEDS::Study_var study = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy(); + if ( study->_is_nil() ) + THROW_SALOME_CORBA_EXCEPTION + ( "ConnectedElements_i::SetThreshold(): NULL current study", SALOME::BAD_PARAM ); + SALOMEDS::SObject_wrap sobj = study->FindObjectID( threshold ); + if ( sobj->_is_nil() ) + THROW_SALOME_CORBA_EXCEPTION + ( "ConnectedElements_i::SetThreshold(): invalid vertex study entry", SALOME::BAD_PARAM ); + CORBA::Object_var obj = sobj->GetObject(); + GEOM::GEOM_Object_var vertex = GEOM::GEOM_Object::_narrow( obj ); + if ( vertex->_is_nil() ) + THROW_SALOME_CORBA_EXCEPTION + ( "ConnectedElements_i::SetThreshold(): no GEOM_Object in SObject", SALOME::BAD_PARAM ); + SetVertex( vertex ); + break; + } + case SMESH::ConnectedElements::NODE: // read a node ID //////////////////////////// + { + char* endptr; + int id = strtol( threshold, &endptr, 10 ); + if ( threshold == endptr ) + THROW_SALOME_CORBA_EXCEPTION + ( "ConnectedElements_i::SetThreshold(): invalid node ID", SALOME::BAD_PARAM ); + SetNode( id ); + break; + } + default: + THROW_SALOME_CORBA_EXCEPTION + ( "ConnectedElements_i::SetThreshold(): invalid ThresholdType", SALOME::BAD_PARAM ); + } +} + +char* ConnectedElements_i::GetThreshold ( SMESH::ConnectedElements::ThresholdType& type ) { - return SMESH::FT_RangeOfIds; + std::string threshold; + if ( !myVertexID.empty() ) + { + threshold = myVertexID; + type = SMESH::ConnectedElements::VERTEX; + } + else + { + std::vector xyz = myConnectedElementsPtr->GetPoint(); + if ( xyz.size() == 3 ) + { + threshold = SMESH_Comment( xyz[0] ) << "; " << xyz[1] << "; " << xyz[2]; + type = SMESH::ConnectedElements::POINT; + } + else + { + threshold = SMESH_Comment( myConnectedElementsPtr->GetNode() ); + type = SMESH::ConnectedElements::NODE; + } + } + return CORBA::string_dup( threshold.c_str() ); } /* @@ -996,12 +1610,13 @@ Comparator_i::Comparator_i(): Comparator_i::~Comparator_i() { if ( myNumericalFunctor ) - myNumericalFunctor->Destroy(); + myNumericalFunctor->UnRegister(); } void Comparator_i::SetMargin( CORBA::Double theValue ) { myComparatorPtr->SetMargin( theValue ); + TPythonDump()<Destroy(); + myNumericalFunctor->UnRegister(); - myNumericalFunctor = dynamic_cast( SMESH_Gen_i::GetServant( theFunct ).in() ); + myNumericalFunctor = DownCast(theFunct); if ( myNumericalFunctor ) { myComparatorPtr->SetNumFunctor( myNumericalFunctor->GetNumericalFunctor() ); myNumericalFunctor->Register(); + TPythonDump()<SetTolerance( theToler ); + TPythonDump()<Destroy(); + myPredicate->UnRegister(); } -void LogicalNOT_i::SetPredicate( Predicate_ptr thePred ) +void LogicalNOT_i::SetPredicate( Predicate_ptr thePredicate ) { if ( myPredicate ) - myPredicate->Destroy(); + myPredicate->UnRegister(); - myPredicate = dynamic_cast( SMESH_Gen_i::GetServant( thePred ).in() ); + myPredicate = SMESH::GetPredicate(thePredicate); if ( myPredicate ){ myLogicalNOTPtr->SetPredicate(myPredicate->GetPredicate()); myPredicate->Register(); + TPythonDump()<Destroy(); + myPredicate1->UnRegister(); if ( myPredicate2 ) - myPredicate2->Destroy(); + myPredicate2->UnRegister(); } void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh ) @@ -1162,26 +1780,28 @@ void LogicalBinary_i::SetMesh( SMESH_Mesh_ptr theMesh ) void LogicalBinary_i::SetPredicate1( Predicate_ptr thePredicate ) { if ( myPredicate1 ) - myPredicate1->Destroy(); + myPredicate1->UnRegister(); - myPredicate1 = dynamic_cast( SMESH_Gen_i::GetServant( thePredicate ).in() ); + myPredicate1 = SMESH::GetPredicate(thePredicate); if ( myPredicate1 ){ myLogicalBinaryPtr->SetPredicate1(myPredicate1->GetPredicate()); myPredicate1->Register(); + TPythonDump()<Destroy(); + myPredicate2->UnRegister(); - myPredicate2 = dynamic_cast( SMESH_Gen_i::GetServant( thePredicate ).in() ); + myPredicate2 = SMESH::GetPredicate(thePredicate); if ( myPredicate2 ){ myLogicalBinaryPtr->SetPredicate2(myPredicate2->GetPredicate()); myPredicate2->Register(); + TPythonDump()<activate_object( this ); + //Base class Salome_GenericObject do it inmplicitly by overriding PortableServer::POA_ptr _default_POA() method + //PortableServer::ObjectId_var anObjectId = + // SMESH_Gen_i::GetPOA()->activate_object( this ); +} + + +FilterManager_i::~FilterManager_i() +{ + //TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); + TPythonDump()<_this(); return anObj._retn(); } -CORBA::Boolean FilterManager_i::DeleteLibrary( const char* aFileName ) -{ - return remove( aFileName ) ? false : true; + +/* + FILTER +*/ + +//======================================================================= +// name : Filter_i::Filter_i +// Purpose : Constructor +//======================================================================= +Filter_i::Filter_i() +: myPredicate( NULL ) +{} + +//======================================================================= +// name : Filter_i::~Filter_i +// Purpose : Destructor +//======================================================================= +Filter_i::~Filter_i() +{ + if ( myPredicate ) + myPredicate->UnRegister(); + + if(!CORBA::is_nil(myMesh)) + myMesh->UnRegister(); + + //TPythonDump()<UnRegister(); + + myPredicate = SMESH::GetPredicate(thePredicate); + + if ( myPredicate ) + { + myFilter.SetPredicate( myPredicate->GetPredicate() ); + myPredicate->Register(); + if ( const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh)) + myPredicate->GetPredicate()->SetMesh( aMesh ); + TPythonDump()<::iterator i = myWaiters.begin(); + for ( ; i != myWaiters.end(); ++i ) + (*i)->PredicateChanged(); +} + +//======================================================================= +// name : Filter_i::GetElementType +// Purpose : Get entity type +//======================================================================= +SMESH::ElementType Filter_i::GetElementType() +{ + return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL; +} + +//======================================================================= +// name : Filter_i::SetMesh +// Purpose : Set mesh +//======================================================================= +void +Filter_i:: +SetMesh( SMESH_Mesh_ptr theMesh ) +{ + if(!CORBA::is_nil(theMesh)) + theMesh->Register(); + + if(!CORBA::is_nil(myMesh)) + myMesh->UnRegister(); + + myMesh = SMESH_Mesh::_duplicate( theMesh ); + TPythonDump()<GetPredicate()->SetMesh( aMesh ); +} + +SMESH::long_array* +Filter_i:: +GetIDs() +{ + return GetElementsId(myMesh); +} + +//======================================================================= +// name : Filter_i::GetElementsId +// Purpose : Get ids of entities +//======================================================================= +void +Filter_i:: +GetElementsId( Predicate_i* thePredicate, + const SMDS_Mesh* theMesh, + Controls::Filter::TIdSequence& theSequence ) +{ + if (thePredicate) + Controls::Filter::GetElementsId(theMesh,thePredicate->GetPredicate(),theSequence); +} + +void +Filter_i:: +GetElementsId( Predicate_i* thePredicate, + SMESH_Mesh_ptr theMesh, + Controls::Filter::TIdSequence& theSequence ) +{ + if (thePredicate) + if(const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh)) + Controls::Filter::GetElementsId(aMesh,thePredicate->GetPredicate(),theSequence); +} + +SMESH::long_array* +Filter_i:: +GetElementsId( SMESH_Mesh_ptr theMesh ) +{ + SMESH::long_array_var anArray = new SMESH::long_array; + if(!CORBA::is_nil(theMesh) && myPredicate){ + Controls::Filter::TIdSequence aSequence; + GetElementsId(myPredicate,theMesh,aSequence); + long i = 0, iEnd = aSequence.size(); + anArray->length( iEnd ); + for ( ; i < iEnd; i++ ) + anArray[ i ] = aSequence[i]; + } + return anArray._retn(); +} + +//============================================================================= +/*! + * \brief Returns number of mesh elements per each \a EntityType + */ +//============================================================================= + +SMESH::long_array* ::Filter_i::GetMeshInfo() +{ + SMESH::long_array_var aRes = new SMESH::long_array(); + aRes->length(SMESH::Entity_Last); + for (int i = 0; i < SMESH::Entity_Last; i++) + aRes[i] = 0; + + if ( !CORBA::is_nil(myMesh) && myPredicate ) + { + const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh); + SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() )); + while ( it->more() ) + { + const SMDS_MeshElement* anElem = it->next(); + if ( myPredicate->IsSatisfy( anElem->GetID() ) ) + aRes[ anElem->GetEntityType() ]++; + } + } + + return aRes._retn(); } //============================================================================= /*! - * SMESH_Gen_i::CreateFilterManager - * - * Create filter manager + * \brief Returns number of mesh elements of each \a ElementType */ //============================================================================= -SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager() +SMESH::long_array* ::Filter_i::GetNbElementsByType() { - SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i(); - SMESH::FilterManager_var anObj = aFilter->_this(); - return anObj._retn(); -} + SMESH::long_array_var aRes = new SMESH::long_array(); + aRes->length(SMESH::NB_ELEMENT_TYPES); + for (int i = 0; i < SMESH::NB_ELEMENT_TYPES; i++) + aRes[i] = 0; + if ( !CORBA::is_nil(myMesh) && myPredicate ) { + const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh); + SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() )); + CORBA::Long& nbElems = aRes[ GetElementType() ]; + while ( it->more() ) + { + const SMDS_MeshElement* anElem = it->next(); + if ( myPredicate->IsSatisfy( anElem->GetID() ) ) + nbElems++; + } + } -/* - FILTER -*/ + return aRes._retn(); +} -//======================================================================= -// name : Filter_i::Filter_i -// Purpose : Constructor -//======================================================================= -Filter_i::Filter_i() -: myPredicate( NULL ) -{} -//======================================================================= -// name : Filter_i::~Filter_i -// Purpose : Destructor -//======================================================================= -Filter_i::~Filter_i() -{ - if ( myPredicate ) - myPredicate->Destroy(); -} +//================================================================================ +/*! + * \brief Return GetElementType() within an array + * Implement SMESH_IDSource interface + */ +//================================================================================ -//======================================================================= -// name : Filter_i::SetPredicate -// Purpose : Set predicate -//======================================================================= -void Filter_i::SetPredicate( Predicate_ptr thePredicate ) +SMESH::array_of_ElementType* Filter_i::GetTypes() { - if ( myPredicate ) - myPredicate->Destroy(); - - myPredicate = dynamic_cast( SMESH_Gen_i::GetServant( thePredicate ).in() ); + SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType; - if ( myPredicate ) + // check if any element passes through the filter + if ( !CORBA::is_nil(myMesh) && myPredicate ) { - myFilter.SetPredicate( myPredicate->GetPredicate() ); - myPredicate->Register(); + const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh); + SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() )); + bool satisfies = false; + while ( !satisfies && it->more() ) + satisfies = myPredicate->IsSatisfy( it->next()->GetID() ); + if ( satisfies ) { + types->length( 1 ); + types[0] = GetElementType(); + } } + return types._retn(); } //======================================================================= -// name : Filter_i::GetElementType -// Purpose : Get entity type +//function : GetMesh +//purpose : Returns mesh //======================================================================= -SMESH::ElementType Filter_i::GetElementType() + +SMESH::SMESH_Mesh_ptr Filter_i::GetMesh() { - return myPredicate != 0 ? myPredicate->GetElementType() : SMESH::ALL; + return SMESH_Mesh::_duplicate( myMesh ); } //======================================================================= -// name : Filter_i::SetMesh -// Purpose : Set mesh +//function : GetVtkUgStream +//purpose : Return data vtk unstructured grid (not implemented) //======================================================================= -void Filter_i::SetMesh( SMESH_Mesh_ptr theMesh ) + +SALOMEDS::TMPFile* Filter_i::GetVtkUgStream() { - if ( myPredicate ) - myPredicate->SetMesh( theMesh ); + SALOMEDS::TMPFile_var SeqFile; + return SeqFile._retn(); } -//======================================================================= -// name : Filter_i::GetElementsId -// Purpose : Get ids of entities -//======================================================================= -SMESH::long_array* Filter_i::GetElementsId( SMESH_Mesh_ptr theMesh ) -{ - SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(theMesh); - Controls::Filter::TIdSequence aSequence = myFilter.GetElementsId(aMesh); +//================================================================================ +/*! + * \brief Stores an object to be notified on change of predicate + */ +//================================================================================ - SMESH::long_array_var anArray = new SMESH::long_array; - long i = 0, iEnd = aSequence.size(); +void Filter_i::AddWaiter( TPredicateChangeWaiter* waiter ) +{ + if ( waiter ) + myWaiters.push_back( waiter ); +} - anArray->length( iEnd ); - for ( ; i < iEnd; i++ ) - anArray[ i ] = aSequence[i]; +//================================================================================ +/*! + * \brief Removes an object to be notified on change of predicate + */ +//================================================================================ - return anArray._retn(); +void Filter_i::RemoveWaiter( TPredicateChangeWaiter* waiter ) +{ + myWaiters.remove( waiter ); } //======================================================================= @@ -1552,78 +2562,115 @@ static inline bool getCriteria( Predicate_i* thePred, switch ( aFType ) { - case FT_FreeBorders: - case FT_FreeEdges: + case FT_LogicalNOT: + { + Predicate_i* aPred = ( dynamic_cast( thePred ) )->GetPredicate_i(); + getCriteria( aPred, theCriteria ); + theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT; + } + return true; + + case FT_LogicalAND: + case FT_LogicalOR: { - CORBA::ULong i = theCriteria->length(); - theCriteria->length( i + 1 ); + Predicate_i* aPred1 = ( dynamic_cast( thePred ) )->GetPredicate1_i(); + Predicate_i* aPred2 = ( dynamic_cast( thePred ) )->GetPredicate2_i(); + if ( !getCriteria( aPred1, theCriteria ) ) + return false; + theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType; + return getCriteria( aPred2, theCriteria ); + } + case FT_Undefined: + return false; + } + + // resize theCriteria + CORBA::ULong i = theCriteria->length(); + theCriteria->length( i + 1 ); + theCriteria[ i ] = createCriterion(); - theCriteria[ i ] = createCriterion(); + // set members of the added Criterion - theCriteria[ i ].Type = aFType; - theCriteria[ i ].TypeOfElement = thePred->GetElementType(); + theCriteria[ i ].Type = aFType; + theCriteria[ i ].TypeOfElement = thePred->GetElementType(); + + switch ( aFType ) + { + case FT_FreeBorders: + case FT_FreeEdges: + case FT_FreeFaces: + case FT_LinearOrQuadratic: + case FT_FreeNodes: + case FT_EqualEdges: + case FT_EqualFaces: + case FT_EqualVolumes: + case FT_BadOrientedVolume: + case FT_BareBorderVolume: + case FT_BareBorderFace: + case FT_OverConstrainedVolume: + case FT_OverConstrainedFace: + { return true; } case FT_BelongToGeom: { BelongToGeom_i* aPred = dynamic_cast( thePred ); - - CORBA::ULong i = theCriteria->length(); - theCriteria->length( i + 1 ); - - theCriteria[ i ] = createCriterion(); - - theCriteria[ i ].Type = FT_BelongToGeom; theCriteria[ i ].ThresholdStr = aPred->GetShapeName(); - theCriteria[ i ].TypeOfElement = aPred->GetElementType(); - + theCriteria[ i ].ThresholdID = aPred->GetShapeID(); + theCriteria[ i ].Tolerance = aPred->GetTolerance(); return true; } case FT_BelongToPlane: case FT_BelongToCylinder: + case FT_BelongToGenSurface: { BelongToSurface_i* aPred = dynamic_cast( thePred ); - - CORBA::ULong i = theCriteria->length(); - theCriteria->length( i + 1 ); - - theCriteria[ i ] = createCriterion(); - - theCriteria[ i ].Type = aFType; theCriteria[ i ].ThresholdStr = aPred->GetShapeName(); - theCriteria[ i ].TypeOfElement = aPred->GetElementType(); + theCriteria[ i ].ThresholdID = aPred->GetShapeID(); theCriteria[ i ].Tolerance = aPred->GetTolerance(); - return true; } - case FT_LyingOnGeom: + case FT_LyingOnGeom: { LyingOnGeom_i* aPred = dynamic_cast( thePred ); - - CORBA::ULong i = theCriteria->length(); - theCriteria->length( i + 1 ); - - theCriteria[ i ] = createCriterion(); - - theCriteria[ i ].Type = FT_LyingOnGeom; theCriteria[ i ].ThresholdStr = aPred->GetShapeName(); - theCriteria[ i ].TypeOfElement = aPred->GetElementType(); - + theCriteria[ i ].ThresholdID = aPred->GetShapeID(); + theCriteria[ i ].Tolerance = aPred->GetTolerance(); + return true; + } + case FT_CoplanarFaces: + { + CoplanarFaces_i* aPred = dynamic_cast( thePred ); + theCriteria[ i ].ThresholdID = aPred->GetFaceAsString(); + theCriteria[ i ].Tolerance = aPred->GetTolerance(); + return true; + } + case FT_ConnectedElements: + { + ConnectedElements_i* aPred = dynamic_cast( thePred ); + SMESH::ConnectedElements::ThresholdType type; + CORBA::String_var threshold = aPred->GetThreshold( type ); + switch ( type ) { + case SMESH::ConnectedElements::POINT: + theCriteria[ i ].ThresholdStr = threshold; break; + case SMESH::ConnectedElements::VERTEX: + theCriteria[ i ].ThresholdID = threshold; break; + case SMESH::ConnectedElements::NODE: + theCriteria[ i ].Threshold = atof( threshold.in() ); break; + default:; + } + return true; + } + case FT_EqualNodes: + { + EqualNodes_i* aPred = dynamic_cast( thePred ); + theCriteria[ i ].Tolerance = aPred->GetTolerance(); return true; } case FT_RangeOfIds: { RangeOfIds_i* aPred = dynamic_cast( thePred ); - - CORBA::ULong i = theCriteria->length(); - theCriteria->length( i + 1 ); - - theCriteria[ i ] = createCriterion(); - - theCriteria[ i ].Type = FT_RangeOfIds; theCriteria[ i ].ThresholdStr = aPred->GetRangeStr(); - theCriteria[ i ].TypeOfElement = aPred->GetElementType(); - return true; } case FT_LessThan: @@ -1631,46 +2678,34 @@ static inline bool getCriteria( Predicate_i* thePred, case FT_EqualTo: { Comparator_i* aCompar = dynamic_cast( thePred ); - - CORBA::ULong i = theCriteria->length(); - theCriteria->length( i + 1 ); - - theCriteria[ i ] = createCriterion(); - theCriteria[ i ].Type = aCompar->GetNumFunctor_i()->GetFunctorType(); theCriteria[ i ].Compare = aFType; theCriteria[ i ].Threshold = aCompar->GetMargin(); - theCriteria[ i ].TypeOfElement = aCompar->GetElementType(); - if ( aFType == FT_EqualTo ) { EqualTo_i* aCompar = dynamic_cast( thePred ); theCriteria[ i ].Tolerance = aCompar->GetTolerance(); } + return true; } - return true; - - case FT_LogicalNOT: + case FT_GroupColor: { - Predicate_i* aPred = ( dynamic_cast( thePred ) )->GetPredicate_i(); - getCriteria( aPred, theCriteria ); - theCriteria[ theCriteria->length() - 1 ].UnaryOp = FT_LogicalNOT; + GroupColor_i* aPred = dynamic_cast( thePred ); + theCriteria[ i ].ThresholdStr = aPred->GetColorStr(); + return true; } - return true; - - case FT_LogicalAND: - case FT_LogicalOR: + case FT_ElemGeomType: { - Predicate_i* aPred1 = ( dynamic_cast( thePred ) )->GetPredicate1_i(); - Predicate_i* aPred2 = ( dynamic_cast( thePred ) )->GetPredicate2_i(); - if ( !getCriteria( aPred1, theCriteria ) ) - return false; - theCriteria[ theCriteria->length() - 1 ].BinaryOp = aFType; - return getCriteria( aPred2, theCriteria ); + ElemGeomType_i* aPred = dynamic_cast( thePred ); + theCriteria[ i ].Threshold = (double)aPred->GetGeometryType(); + return true; + } + case FT_EntityType: + { + ElemEntityType_i* aPred = dynamic_cast( thePred ); + theCriteria[ i ].Threshold = (double)aPred->GetEntityType(); + return true; } - - case FT_Undefined: - return false; default: return false; } @@ -1692,15 +2727,15 @@ CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria ) //======================================================================= CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria ) { - if ( myPredicate != 0 ) - myPredicate->Destroy(); + SetPredicate( SMESH::Predicate::_nil() ); - SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i(); - FilterManager_ptr aFilterMgr = aFilter->_this(); + SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i(); + FilterManager_ptr aFilterMgr = aFilter->_this(); // CREATE two lists ( PREDICATES and LOG OP ) // Criterion + TPythonDump()<<"aCriteria = []"; std::list aPredicates; std::list aBinaries; for ( int i = 0, n = theCriteria.length(); i < n; i++ ) @@ -1708,26 +2743,43 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria int aCriterion = theCriteria[ i ].Type; int aCompare = theCriteria[ i ].Compare; double aThreshold = theCriteria[ i ].Threshold; + const char* aThresholdStr = theCriteria[ i ].ThresholdStr; + const char* aThresholdID = theCriteria[ i ].ThresholdID; int aUnary = theCriteria[ i ].UnaryOp; int aBinary = theCriteria[ i ].BinaryOp; double aTolerance = theCriteria[ i ].Tolerance; - const char* aThresholdStr = theCriteria[ i ].ThresholdStr; ElementType aTypeOfElem = theCriteria[ i ].TypeOfElement; long aPrecision = theCriteria[ i ].Precision; - + + { + TPythonDump pd; + pd << "aCriterion = SMESH.Filter.Criterion(" + << aCriterion << ", " + << aCompare << ", " + << aThreshold << ", '" + << aThresholdStr << "', '" + << aThresholdID << "', " + << aUnary << ", " + << aBinary << ", " + << aTolerance << ", " + << aTypeOfElem << ", " + << aPrecision << ")"; + } + TPythonDump pd; + SMESH::Predicate_ptr aPredicate = SMESH::Predicate::_nil(); SMESH::NumericalFunctor_ptr aFunctor = SMESH::NumericalFunctor::_nil(); switch ( aCriterion ) { // Functors - + case SMESH::FT_MultiConnection: aFunctor = aFilterMgr->CreateMultiConnection(); break; case SMESH::FT_MultiConnection2D: - aFunctor = aFilterMgr->CreateMultiConnection2D(); - break; + aFunctor = aFilterMgr->CreateMultiConnection2D(); + break; case SMESH::FT_Length: aFunctor = aFilterMgr->CreateLength(); break; @@ -1755,6 +2807,18 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria case SMESH::FT_Area: aFunctor = aFilterMgr->CreateArea(); break; + case SMESH::FT_Volume3D: + aFunctor = aFilterMgr->CreateVolume3D(); + break; + case SMESH::FT_MaxElementLength2D: + aFunctor = aFilterMgr->CreateMaxElementLength2D(); + break; + case SMESH::FT_MaxElementLength3D: + aFunctor = aFilterMgr->CreateMaxElementLength3D(); + break; + case SMESH::FT_BallDiameter: + aFunctor = aFilterMgr->CreateBallDiameter(); + break; // Predicates @@ -1764,23 +2828,51 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria case SMESH::FT_FreeEdges: aPredicate = aFilterMgr->CreateFreeEdges(); break; + case SMESH::FT_FreeFaces: + aPredicate = aFilterMgr->CreateFreeFaces(); + break; + case SMESH::FT_FreeNodes: + aPredicate = aFilterMgr->CreateFreeNodes(); + break; + case SMESH::FT_EqualNodes: + { + SMESH::EqualNodes_ptr pred = aFilterMgr->CreateEqualNodes(); + pred->SetTolerance( aTolerance ); + aPredicate = pred; + break; + } + case SMESH::FT_EqualEdges: + aPredicate = aFilterMgr->CreateEqualEdges(); + break; + case SMESH::FT_EqualFaces: + aPredicate = aFilterMgr->CreateEqualFaces(); + break; + case SMESH::FT_EqualVolumes: + aPredicate = aFilterMgr->CreateEqualVolumes(); + break; case SMESH::FT_BelongToGeom: { SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom(); tmpPred->SetElementType( aTypeOfElem ); - tmpPred->SetShapeName( aThresholdStr ); + tmpPred->SetShape( aThresholdID, aThresholdStr ); + tmpPred->SetTolerance( aTolerance ); aPredicate = tmpPred; } break; case SMESH::FT_BelongToPlane: case SMESH::FT_BelongToCylinder: + case SMESH::FT_BelongToGenSurface: { SMESH::BelongToSurface_ptr tmpPred; - if ( aCriterion == SMESH::FT_BelongToPlane ) - tmpPred = aFilterMgr->CreateBelongToPlane(); - else - tmpPred = aFilterMgr->CreateBelongToCylinder(); - tmpPred->SetShapeName( aThresholdStr, aTypeOfElem ); + switch ( aCriterion ) { + case SMESH::FT_BelongToPlane: + tmpPred = aFilterMgr->CreateBelongToPlane(); break; + case SMESH::FT_BelongToCylinder: + tmpPred = aFilterMgr->CreateBelongToCylinder(); break; + default: + tmpPred = aFilterMgr->CreateBelongToGenSurface(); + } + tmpPred->SetShape( aThresholdID, aThresholdStr, aTypeOfElem ); tmpPred->SetTolerance( aTolerance ); aPredicate = tmpPred; } @@ -1789,10 +2881,11 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria { SMESH::LyingOnGeom_ptr tmpPred = aFilterMgr->CreateLyingOnGeom(); tmpPred->SetElementType( aTypeOfElem ); - tmpPred->SetShapeName( aThresholdStr ); + tmpPred->SetShape( aThresholdID, aThresholdStr ); + tmpPred->SetTolerance( aTolerance ); aPredicate = tmpPred; } - break; + break; case SMESH::FT_RangeOfIds: { SMESH::RangeOfIds_ptr tmpPred = aFilterMgr->CreateRangeOfIds(); @@ -1801,7 +2894,84 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria aPredicate = tmpPred; } break; - + case SMESH::FT_BadOrientedVolume: + { + aPredicate = aFilterMgr->CreateBadOrientedVolume(); + } + break; + case SMESH::FT_BareBorderVolume: + { + aPredicate = aFilterMgr->CreateBareBorderVolume(); + } + break; + case SMESH::FT_BareBorderFace: + { + aPredicate = aFilterMgr->CreateBareBorderFace(); + } + break; + case SMESH::FT_OverConstrainedVolume: + { + aPredicate = aFilterMgr->CreateOverConstrainedVolume(); + } + break; + case SMESH::FT_OverConstrainedFace: + { + aPredicate = aFilterMgr->CreateOverConstrainedFace(); + } + break; + case SMESH::FT_LinearOrQuadratic: + { + SMESH::LinearOrQuadratic_ptr tmpPred = aFilterMgr->CreateLinearOrQuadratic(); + tmpPred->SetElementType( aTypeOfElem ); + aPredicate = tmpPred; + break; + } + case SMESH::FT_GroupColor: + { + SMESH::GroupColor_ptr tmpPred = aFilterMgr->CreateGroupColor(); + tmpPred->SetElementType( aTypeOfElem ); + tmpPred->SetColorStr( aThresholdStr ); + aPredicate = tmpPred; + break; + } + case SMESH::FT_ElemGeomType: + { + SMESH::ElemGeomType_ptr tmpPred = aFilterMgr->CreateElemGeomType(); + tmpPred->SetElementType( aTypeOfElem ); + tmpPred->SetGeometryType( (GeometryType)(int)(aThreshold + 0.5) ); + aPredicate = tmpPred; + break; + } + case SMESH::FT_EntityType: + { + SMESH::ElemEntityType_ptr tmpPred = aFilterMgr->CreateElemEntityType(); + tmpPred->SetElementType( aTypeOfElem ); + tmpPred->SetEntityType( EntityType( (int (aThreshold + 0.5)))); + aPredicate = tmpPred; + break; + } + case SMESH::FT_CoplanarFaces: + { + SMESH::CoplanarFaces_ptr tmpPred = aFilterMgr->CreateCoplanarFaces(); + tmpPred->SetFace( atol (aThresholdID )); + tmpPred->SetTolerance( aTolerance ); + aPredicate = tmpPred; + break; + } + case SMESH::FT_ConnectedElements: + { + SMESH::ConnectedElements_ptr tmpPred = aFilterMgr->CreateConnectedElements(); + if ( strlen( aThresholdID ) > 0 ) // shape ID + tmpPred->SetThreshold( aThresholdID, SMESH::ConnectedElements::VERTEX ); + else if ( strlen( aThresholdStr ) > 0 ) // point coords + tmpPred->SetThreshold( aThresholdStr, SMESH::ConnectedElements::POINT ); + else if ( aThreshold >= 1 ) + tmpPred->SetNode( (CORBA::Long) aThreshold ); // node ID + tmpPred->SetElementType( aTypeOfElem ); + aPredicate = tmpPred; + break; + } + default: continue; } @@ -1845,8 +3015,10 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria // logical op aPredicates.push_back( aPredicate ); aBinaries.push_back( aBinary ); + pd <<"aCriteria.append(aCriterion)"; } // end of for + TPythonDump pd; pd<_is_nil() ) + aResPredicate->UnRegister(); return !aResPredicate->_is_nil(); } @@ -1931,6 +3107,8 @@ Predicate_ptr Filter_i::GetPredicate() else { SMESH::Predicate_var anObj = myPredicate->_this(); + // if ( SMESH::Functor_i* fun = SMESH::DownCast( anObj )) + // TPythonDump() << fun << " = " << this << ".GetPredicate()"; return anObj._retn(); } } @@ -1952,7 +3130,7 @@ Predicate_ptr Filter_i::GetPredicate() // name : toString // Purpose : Convert bool to LDOMString //======================================================================= -static inline LDOMString toString( const bool val ) +static inline LDOMString toString( CORBA::Boolean val ) { return val ? "logical not" : ""; } @@ -1970,7 +3148,7 @@ static inline bool toBool( const LDOMString& theStr ) // name : toString // Purpose : Convert double to LDOMString //======================================================================= -static inline LDOMString toString( const double val ) +static inline LDOMString toString( CORBA::Double val ) { char a[ 255 ]; sprintf( a, "%e", val ); @@ -1990,7 +3168,7 @@ static inline double toDouble( const LDOMString& theStr ) // name : toString // Purpose : Convert functor type to LDOMString //======================================================================= -static inline LDOMString toString( const long theType ) +static inline LDOMString toString( CORBA::Long theType ) { switch ( theType ) { @@ -2000,23 +3178,42 @@ static inline LDOMString toString( const long theType ) case FT_Taper : return "Taper"; case FT_Skew : return "Skew"; case FT_Area : return "Area"; + case FT_Volume3D : return "Volume3D"; + case FT_MaxElementLength2D: return "Max element length 2D"; + case FT_MaxElementLength3D: return "Max element length 3D"; case FT_BelongToGeom : return "Belong to Geom"; case FT_BelongToPlane : return "Belong to Plane"; case FT_BelongToCylinder: return "Belong to Cylinder"; + case FT_BelongToGenSurface: return "Belong to Generic Surface"; case FT_LyingOnGeom : return "Lying on Geom"; + case FT_BadOrientedVolume:return "Bad Oriented Volume"; + case FT_BareBorderVolume: return "Volumes with bare border"; + case FT_BareBorderFace : return "Faces with bare border"; + case FT_OverConstrainedVolume: return "Over-constrained Volumes"; + case FT_OverConstrainedFace : return "Over-constrained Faces"; case FT_RangeOfIds : return "Range of IDs"; case FT_FreeBorders : return "Free borders"; case FT_FreeEdges : return "Free edges"; + case FT_FreeFaces : return "Free faces"; + case FT_FreeNodes : return "Free nodes"; + case FT_EqualNodes : return "Equal nodes"; + case FT_EqualEdges : return "Equal edges"; + case FT_EqualFaces : return "Equal faces"; + case FT_EqualVolumes : return "Equal volumes"; case FT_MultiConnection : return "Borders at multi-connections"; - case FT_MultiConnection2D: return "Borders at multi-connections 2D"; + case FT_MultiConnection2D:return "Borders at multi-connections 2D"; case FT_Length : return "Length"; - case FT_Length2D : return "Length2D"; + case FT_Length2D : return "Length 2D"; case FT_LessThan : return "Less than"; case FT_MoreThan : return "More than"; case FT_EqualTo : return "Equal to"; case FT_LogicalNOT : return "Not"; case FT_LogicalAND : return "And"; case FT_LogicalOR : return "Or"; + case FT_GroupColor : return "Color of Group"; + case FT_LinearOrQuadratic : return "Linear or Quadratic"; + case FT_ElemGeomType : return "Element geomtry type"; + case FT_EntityType : return "Entity type"; case FT_Undefined : return ""; default : return ""; } @@ -2034,23 +3231,42 @@ static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr ) else if ( theStr.equals( "Taper" ) ) return FT_Taper; else if ( theStr.equals( "Skew" ) ) return FT_Skew; else if ( theStr.equals( "Area" ) ) return FT_Area; + else if ( theStr.equals( "Volume3D" ) ) return FT_Volume3D; + else if ( theStr.equals( "Max element length 2D" ) ) return FT_MaxElementLength2D; + else if ( theStr.equals( "Max element length 3D" ) ) return FT_MaxElementLength3D; else if ( theStr.equals( "Belong to Geom" ) ) return FT_BelongToGeom; else if ( theStr.equals( "Belong to Plane" ) ) return FT_BelongToPlane; else if ( theStr.equals( "Belong to Cylinder" ) ) return FT_BelongToCylinder; + else if ( theStr.equals( "Belong to Generic Surface" ) ) return FT_BelongToGenSurface; else if ( theStr.equals( "Lying on Geom" ) ) return FT_LyingOnGeom; else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders; else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges; + else if ( theStr.equals( "Free faces" ) ) return FT_FreeFaces; + else if ( theStr.equals( "Free nodes" ) ) return FT_FreeNodes; + else if ( theStr.equals( "Equal nodes" ) ) return FT_EqualNodes; + else if ( theStr.equals( "Equal edges" ) ) return FT_EqualEdges; + else if ( theStr.equals( "Equal faces" ) ) return FT_EqualFaces; + else if ( theStr.equals( "Equal volumes" ) ) return FT_EqualVolumes; else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection; // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D; else if ( theStr.equals( "Length" ) ) return FT_Length; // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D; else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds; + else if ( theStr.equals( "Bad Oriented Volume" ) ) return FT_BadOrientedVolume; + else if ( theStr.equals( "Volumes with bare border" ) ) return FT_BareBorderVolume; + else if ( theStr.equals( "Faces with bare border" ) ) return FT_BareBorderFace; + else if ( theStr.equals( "Over-constrained Volumes" ) ) return FT_OverConstrainedVolume; + else if ( theStr.equals( "Over-constrained Faces" ) ) return FT_OverConstrainedFace; else if ( theStr.equals( "Less than" ) ) return FT_LessThan; else if ( theStr.equals( "More than" ) ) return FT_MoreThan; else if ( theStr.equals( "Equal to" ) ) return FT_EqualTo; else if ( theStr.equals( "Not" ) ) return FT_LogicalNOT; else if ( theStr.equals( "And" ) ) return FT_LogicalAND; else if ( theStr.equals( "Or" ) ) return FT_LogicalOR; + else if ( theStr.equals( "Color of Group" ) ) return FT_GroupColor; + else if ( theStr.equals( "Linear or Quadratic" ) ) return FT_LinearOrQuadratic; + else if ( theStr.equals( "Element geomtry type" ) ) return FT_ElemGeomType; + else if ( theStr.equals( "Entity type" ) ) return FT_EntityType; else if ( theStr.equals( "" ) ) return FT_Undefined; else return FT_Undefined; } @@ -2150,7 +3366,7 @@ static LDOM_Node getSection( const ElementType theType, const char* aSectionName = getSectionName( theType ); if ( strcmp( aSectionName, "" ) == 0 ) return LDOM_Node(); - + LDOM_NodeList aSections = theDoc.getElementsByTagName( "section" ); LDOM_Node aNode; for ( int i = 0, n = aSections.getLength(); i < n; i++ ) @@ -2202,13 +3418,13 @@ static LDOM_Element createFilterItem( const char* theName, for ( CORBA::ULong i = 0, n = aCriteria->length(); i < n; i++ ) { LDOM_Element aCriterionItem = theDoc.createElement( "criterion" ); - - aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type ) ); - aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) ); - aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) ); - aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) ); - aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) ); + aCriterionItem.setAttribute( ATTR_TYPE , toString( aCriteria[ i ].Type) ); + aCriterionItem.setAttribute( ATTR_COMPARE , toString( aCriteria[ i ].Compare ) ); + aCriterionItem.setAttribute( ATTR_THRESHOLD , toString( aCriteria[ i ].Threshold ) ); + aCriterionItem.setAttribute( ATTR_UNARY , toString( aCriteria[ i ].UnaryOp ) ); + aCriterionItem.setAttribute( ATTR_BINARY , toString( aCriteria[ i ].BinaryOp ) ); + aCriterionItem.setAttribute( ATTR_THRESHOLD_STR, (const char*)aCriteria[ i ].ThresholdStr ); aCriterionItem.setAttribute( ATTR_TOLERANCE , toString( aCriteria[ i ].Tolerance ) ); aCriterionItem.setAttribute( ATTR_ELEMENT_TYPE , @@ -2268,6 +3484,7 @@ FilterLibrary_i::FilterLibrary_i() FilterLibrary_i::~FilterLibrary_i() { delete myFileName; + //TPythonDump()< aCriteria; - + for ( LDOM_Node aCritNode = aFilter.getFirstChild(); !aCritNode.isNull() ; aCritNode = aCritNode.getNextSibling() ) { @@ -2294,14 +3511,14 @@ Filter_ptr FilterLibrary_i::Copy( const char* theFilterName ) const char* aUnaryStr = aCrit->getAttribute( ATTR_UNARY ).GetString(); const char* aBinaryStr = aCrit->getAttribute( ATTR_BINARY ).GetString(); const char* anElemTypeStr = aCrit->getAttribute( ATTR_ELEMENT_TYPE ).GetString(); - + SMESH::Filter::Criterion aCriterion = createCriterion(); aCriterion.Type = toFunctorType( aTypeStr ); aCriterion.Compare = toFunctorType( aCompareStr ); aCriterion.UnaryOp = toFunctorType( aUnaryStr ); aCriterion.BinaryOp = toFunctorType( aBinaryStr ); - + aCriterion.TypeOfElement = toElementType( anElemTypeStr ); LDOMString str = aCrit->getAttribute( ATTR_THRESHOLD ); @@ -2328,16 +3545,18 @@ Filter_ptr FilterLibrary_i::Copy( const char* theFilterName ) SMESH::Filter::Criteria_var aCriteriaVar = new SMESH::Filter::Criteria; aCriteriaVar->length( aCriteria.size() ); - + CORBA::ULong i = 0; std::list::iterator anIter = aCriteria.begin(); - + for( ; anIter != aCriteria.end(); ++anIter ) aCriteriaVar[ i++ ] = *anIter; aRes = myFilterMgr->CreateFilter(); aRes->SetCriteria( aCriteriaVar.inout() ); + TPythonDump()<(theFilter)) + TPythonDump()<CreateFilter(); - + LDOM_Element aFilterItem = createFilterItem( theFilterName, aFilter, myDoc ); if ( aFilterItem.isNull() ) return false; else { aSection.appendChild( aFilterItem ); + TPythonDump()<(theFilter)) + TPythonDump()< SMESH::FT_Undefined ) + return "FT_Undefined"; + return getFunctNames()[ ft ]; +} + +//================================================================================ +/*! + * \brief Converts a string to FunctorType. This is reverse of FunctorTypeToString() + */ +//================================================================================ + +SMESH::FunctorType SMESH::StringToFunctorType(const char* str) +{ + std::string name( str + 3 ); // skip "FT_" + const char** functNames = getFunctNames(); + int ft = 0; + for ( ; ft < SMESH::FT_Undefined; ++ft ) + if ( name == ( functNames[ft] + 3 )) + break; + + //ASSERT( strcmp( str, FunctorTypeToString( SMESH::FunctorType( ft ))) == 0 ); + + return SMESH::FunctorType( ft ); +}