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=d81f7f667faa5ea81bd417a9acafd1ef577fb002;hp=e52d29b558c5259311793762df8a11de1961aa31;hb=fa9a9581d37a45a53111f7df9ae5429c9692851f;hpb=f3171e5c4ed477e85e8b4c8ad5bef45f911966e9 diff --git a/src/SMESH_I/SMESH_Filter_i.cxx b/src/SMESH_I/SMESH_Filter_i.cxx index e52d29b55..d81f7f667 100644 --- a/src/SMESH_I/SMESH_Filter_i.cxx +++ b/src/SMESH_I/SMESH_Filter_i.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2014 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 @@ -6,7 +6,7 @@ // 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. +// 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 @@ -55,12 +55,9 @@ #include #include #include -#include #include #include -#include #include -#include using namespace SMESH; using namespace SMESH::Controls; @@ -75,358 +72,6 @@ namespace SMESH } } - -/* - Class : BelongToGeom - Description : Predicate for verifying whether entity belongs to - specified geometrical support -*/ - -Controls::BelongToGeom::BelongToGeom() - : myMeshDS(NULL), - myType(SMDSAbs_All), - myIsSubshape(false), - myTolerance(Precision::Confusion()) -{} - -void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh ) -{ - myMeshDS = dynamic_cast(theMesh); - init(); -} - -void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape ) -{ - myShape = theShape; - init(); -} - -static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap, - const TopoDS_Shape& theShape) -{ - if (theMap.Contains(theShape)) return true; - - if (theShape.ShapeType() == TopAbs_COMPOUND || - theShape.ShapeType() == TopAbs_COMPSOLID) - { - TopoDS_Iterator anIt (theShape, Standard_True, Standard_True); - for (; anIt.More(); anIt.Next()) - { - if (!IsSubShape(theMap, anIt.Value())) { - return false; - } - } - return true; - } - - return false; -} - -void Controls::BelongToGeom::init() -{ - if (!myMeshDS || myShape.IsNull()) return; - - // is sub-shape of main shape? - TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh(); - if (aMainShape.IsNull()) { - myIsSubshape = false; - } - else { - TopTools_IndexedMapOfShape aMap; - TopExp::MapShapes(aMainShape, aMap); - myIsSubshape = IsSubShape(aMap, myShape); - } - - if (!myIsSubshape) - { - myElementsOnShapePtr.reset(new Controls::ElementsOnShape()); - myElementsOnShapePtr->SetTolerance(myTolerance); - myElementsOnShapePtr->SetAllNodes(true); // belong, while false means "lays on" - myElementsOnShapePtr->SetMesh(myMeshDS); - myElementsOnShapePtr->SetShape(myShape, myType); - } -} - -static bool IsContains( const 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 (!myIsSubshape) - { - return myElementsOnShapePtr->IsSatisfy(theId); - } - - // Case of submesh - 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; - init(); -} - -SMDSAbs_ElementType Controls::BelongToGeom::GetType() const -{ - return myType; -} - -TopoDS_Shape Controls::BelongToGeom::GetShape() -{ - return myShape; -} - -const SMESHDS_Mesh* Controls::BelongToGeom::GetMeshDS() const -{ - return myMeshDS; -} - -void Controls::BelongToGeom::SetTolerance (double theTolerance) -{ - myTolerance = theTolerance; - if (!myIsSubshape) - init(); -} - -double Controls::BelongToGeom::GetTolerance() -{ - return myTolerance; -} - -/* - Class : LyingOnGeom - Description : Predicate for verifying whether entiy lying or partially lying on - specified geometrical support -*/ - -Controls::LyingOnGeom::LyingOnGeom() - : myMeshDS(NULL), - myType(SMDSAbs_All), - myIsSubshape(false), - myTolerance(Precision::Confusion()) -{} - -void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh ) -{ - myMeshDS = dynamic_cast(theMesh); - init(); -} - -void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape ) -{ - myShape = theShape; - init(); -} - -void Controls::LyingOnGeom::init() -{ - if (!myMeshDS || myShape.IsNull()) return; - - // is sub-shape of main shape? - TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh(); - if (aMainShape.IsNull()) { - myIsSubshape = false; - } - else { - TopTools_IndexedMapOfShape aMap; - TopExp::MapShapes(aMainShape, aMap); - myIsSubshape = IsSubShape(aMap, myShape); - } - - if (!myIsSubshape) - { - myElementsOnShapePtr.reset(new Controls::ElementsOnShape()); - myElementsOnShapePtr->SetTolerance(myTolerance); - myElementsOnShapePtr->SetAllNodes(false); // lays on, while true means "belong" - myElementsOnShapePtr->SetMesh(myMeshDS); - myElementsOnShapePtr->SetShape(myShape, myType); - } -} - -bool Controls::LyingOnGeom::IsSatisfy( long theId ) -{ - if ( myMeshDS == 0 || myShape.IsNull() ) - return false; - - if (!myIsSubshape) - { - return myElementsOnShapePtr->IsSatisfy(theId); - } - - // Case of submesh - 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; - init(); -} - -SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const -{ - return myType; -} - -TopoDS_Shape Controls::LyingOnGeom::GetShape() -{ - return myShape; -} - -const SMESHDS_Mesh* Controls::LyingOnGeom::GetMeshDS() const -{ - return myMeshDS; -} - -void Controls::LyingOnGeom::SetTolerance (double theTolerance) -{ - myTolerance = theTolerance; - if (!myIsSubshape) - init(); -} - -double Controls::LyingOnGeom::GetTolerance() -{ - return myTolerance; -} - -bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh* theMeshDS, - const TopoDS_Shape& theShape, - const SMDS_MeshElement* theElem, - TopAbs_ShapeEnum theFindShapeEnum, - TopAbs_ShapeEnum theAvoidShapeEnum ) -{ - if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum)) - return true; - - TopTools_IndexedMapOfShape aSubShapes; - TopExp::MapShapes( theShape, aSubShapes ); - - for (int i = 1; i <= aSubShapes.Extent(); i++) - { - const TopoDS_Shape& aShape = aSubShapes.FindKey(i); - - if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){ - if( aSubMesh->Contains( theElem ) ) - return true; - - 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; - } - } - } - } - return false; -} - - /* AUXILIARY METHODS */ @@ -622,6 +267,7 @@ SMESH::Histogram* NumericalFunctor_i::GetLocalHistogram(CORBA::Short SMESH::DownCast< SMESH::Filter_i* >( object )) { elemIt = SMESH_Mesh_i::GetElements( object, GetElementType() ); + if ( !elemIt ) return histogram._retn(); } else { @@ -3422,8 +3068,8 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria } SetPredicate( aResPredicate ); - - aResPredicate->UnRegister(); + if ( !aResPredicate->_is_nil() ) + aResPredicate->UnRegister(); return !aResPredicate->_is_nil(); }