X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_Filter.cxx;h=95e02173e8edea037f28fc4711fef1cb87bb7dfa;hp=f6c4ae5b5f4b0e0a90ceff2839f3e6d3725db5ad;hb=fda116565e80126f590175c72c859516826f0a63;hpb=e4737e85f0da6d3f90fd08f6be1c2825195fe16f diff --git a/src/SMESHGUI/SMESHGUI_Filter.cxx b/src/SMESHGUI/SMESHGUI_Filter.cxx index f6c4ae5b5..95e02173e 100755 --- a/src/SMESHGUI/SMESHGUI_Filter.cxx +++ b/src/SMESHGUI/SMESHGUI_Filter.cxx @@ -1,42 +1,37 @@ -// SMESHGUI_PredicateFilter : Filters for VTK viewer +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2003-2007 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 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. +// 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 +// 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 +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -// -// -// File : SMESHGUI_Filter.cxx -// Author : Sergey LITONIN -// Module : SMESH +// SMESHGUI_Filter : Filters for VTK viewer +// File : SMESHGUI_Filter.cxx +// Author : Sergey LITONIN, Open CASCADE S.A.S. +// SMESH includes +// #include "SMESHGUI_Filter.h" -#include "SMESHGUI_Utils.h" -#include "SMDS_Mesh.hxx" -#include "SMDS_MeshElement.hxx" -#include "SMDSAbs_ElementType.hxx" -#include +#include "SMESHGUI_Utils.h" -#include -#include -#include "SMESH_Actor.h" -#include "SMESHGUI.h" +#include +#include +#include IMPLEMENT_STANDARD_HANDLE(SMESHGUI_Filter, VTKViewer_Filter) IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_Filter, VTKViewer_Filter) @@ -50,6 +45,12 @@ IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_QuadrangleFilter, SMESHGUI_Filter) IMPLEMENT_STANDARD_HANDLE(SMESHGUI_TriangleFilter, SMESHGUI_Filter) IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_TriangleFilter, SMESHGUI_Filter) +IMPLEMENT_STANDARD_HANDLE(SMESHGUI_FacesFilter, SMESHGUI_Filter) +IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_FacesFilter, SMESHGUI_Filter) + +IMPLEMENT_STANDARD_HANDLE(SMESHGUI_VolumesFilter, SMESHGUI_Filter) +IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_VolumesFilter, SMESHGUI_Filter) + /* Class : SMESHGUI_PredicateFilter Description : Selection filter for VTK viewer. This class aggregate object @@ -77,21 +78,22 @@ bool SMESHGUI_PredicateFilter::IsValid( const int theCellId ) const if ( myActor == 0 || myPred->_is_nil() ) return false; - SMESH_Actor* anActor = ( SMESH_Actor* )myActor; - if ( anActor->GetObject() == 0 ) + SMESH_Actor* anActor = dynamic_cast( myActor ); + if ( !anActor || anActor->GetObject() == 0 ) return false; - + SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh(); - SMESH::ElementType anElemType = myPred->GetElementType(); - int aMeshId = anElemType == SMESH::NODE ? anActor->GetNodeObjId( theCellId ) - : anActor->GetElemObjId( theCellId ); + SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)myPred->GetElementType(); + int aMeshId = anElemType == SMDSAbs_Node ? anActor->GetNodeObjId( theCellId ) + : anActor->GetElemObjId( theCellId ); // if type of element != type of predicate return true because // this predicate is not intended for filtering sush elements - const SMDS_MeshElement* anElem = anElemType == SMESH::NODE ? aMesh->FindNode( aMeshId ) - : aMesh->FindElement( aMeshId ); - if ( anElem != 0 && anElem->GetType() != (SMDSAbs_ElementType)myPred->GetElementType() ) - return true; + const SMDS_MeshElement* anElem = anElemType == SMDSAbs_Node ? aMesh->FindNode( aMeshId ) + : aMesh->FindElement( aMeshId ); + // here we guess that predicate element type can not be All in case of node selection + if ( !anElem || (anElemType != SMDSAbs_All && anElem->GetType() != anElemType) ) + return false; return myPred->IsSatisfy( aMeshId ); } @@ -105,19 +107,20 @@ bool SMESHGUI_PredicateFilter::IsObjValid( const int theObjId ) const if ( myActor == 0 || myPred->_is_nil() ) return false; - SMESH_Actor* anActor = ( SMESH_Actor* )myActor; - if ( anActor->GetObject() == 0 ) + SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor ); + if ( !anActor || anActor->GetObject() == 0 ) return false; - + SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh(); - SMESH::ElementType anElemType = myPred->GetElementType(); - + SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)myPred->GetElementType(); + // if type of element != type of predicate return true because // this predicate is not intended for filtering sush elements - const SMDS_MeshElement* anElem = anElemType == SMESH::NODE ? aMesh->FindNode( theObjId ) - : aMesh->FindElement( theObjId ); - if ( anElem != 0 && anElem->GetType() != (SMDSAbs_ElementType)myPred->GetElementType() ) - return true; + const SMDS_MeshElement* anElem = anElemType == SMDSAbs_Node ? aMesh->FindNode( theObjId ) + : aMesh->FindElement( theObjId ); + // here we guess that predicate element type can not be All in case of node selection + if ( !anElem || (anElemType != SMDSAbs_All && anElem->GetType() != anElemType) ) + return false; return myPred->IsSatisfy( theObjId ); } @@ -128,7 +131,7 @@ bool SMESHGUI_PredicateFilter::IsObjValid( const int theObjId ) const //======================================================================= bool SMESHGUI_PredicateFilter::IsNodeFilter() const { - return GetId() == SMESHGUI_NodeFilter; + return GetId() == SMESH::NodeFilter; } //======================================================================= @@ -152,7 +155,10 @@ void SMESHGUI_PredicateFilter::SetActor( SALOME_Actor* theActor ) if ( myActor != 0 && !myPred->_is_nil() ) { - Handle(SALOME_InteractiveObject) anIO = myActor->getIO(); + SALOME_Actor* sActor = dynamic_cast( myActor ); + Handle(SALOME_InteractiveObject) anIO; + if( sActor ) + anIO = sActor->getIO(); if ( !anIO.IsNull() ) { SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface(anIO); @@ -169,12 +175,12 @@ void SMESHGUI_PredicateFilter::SetActor( SALOME_Actor* theActor ) //======================================================================= int SMESHGUI_PredicateFilter::GetId() const { - if ( myPred->GetElementType() == SMESH::NODE ) return SMESHGUI_NodeFilter; - else if ( myPred->GetElementType() == SMESH::EDGE ) return SMESHGUI_EdgeFilter; - else if ( myPred->GetElementType() == SMESH::FACE ) return SMESHGUI_FaceFilter; - else if ( myPred->GetElementType() == SMESH::VOLUME ) return SMESHGUI_VolumeFilter; - else if ( myPred->GetElementType() == SMESH::ALL ) return SMESHGUI_AllElementsFilter; - else return SMESHGUI_UnknownFilter; + if ( myPred->GetElementType() == SMESH::NODE ) return SMESH::NodeFilter; + else if ( myPred->GetElementType() == SMESH::EDGE ) return SMESH::EdgeFilter; + else if ( myPred->GetElementType() == SMESH::FACE ) return SMESH::FaceFilter; + else if ( myPred->GetElementType() == SMESH::VOLUME ) return SMESH::VolumeFilter; + else if ( myPred->GetElementType() == SMESH::ALL ) return SMESH::AllElementsFilter; + else return SMESH::UnknownFilter; } @@ -205,14 +211,15 @@ bool SMESHGUI_QuadrangleFilter::IsValid( const int theCellId ) const if ( myActor == 0 ) return false; - SMESH_Actor* anActor = ( SMESH_Actor* )myActor; - if ( anActor->GetObject() == 0 ) + SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor ); + if ( !anActor || anActor->GetObject() == 0 ) return false; - + SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh(); const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) ); - - return anElem != 0 ? anElem->GetType() != SMDSAbs_Face || anElem->NbNodes() == 4 : false; + + return anElem && anElem->GetType() == SMDSAbs_Face && + ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 )); } //======================================================================= @@ -224,14 +231,15 @@ bool SMESHGUI_QuadrangleFilter::IsObjValid( const int theObjId ) const if ( myActor == 0 ) return false; - SMESH_Actor* anActor = ( SMESH_Actor* )myActor; - if ( anActor->GetObject() == 0 ) + SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor ); + if ( !anActor || anActor->GetObject() == 0 ) return false; - + SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh(); const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId ); - return anElem != 0 ? anElem->GetType() != SMDSAbs_Face || anElem->NbNodes() == 4 : false; + return anElem && anElem->GetType() == SMDSAbs_Face && + ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 )); } //======================================================================= @@ -241,7 +249,7 @@ bool SMESHGUI_QuadrangleFilter::IsObjValid( const int theObjId ) const //======================================================================= int SMESHGUI_QuadrangleFilter::GetId() const { - return SMESHGUI_QuadFilter; + return SMESH::QuadFilter; } //======================================================================= @@ -282,14 +290,15 @@ bool SMESHGUI_TriangleFilter::IsValid( const int theCellId ) const if ( myActor == 0 ) return false; - SMESH_Actor* anActor = ( SMESH_Actor* )myActor; - if ( anActor->GetObject() == 0 ) + SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor ); + if ( !anActor || anActor->GetObject() == 0 ) return false; - + SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh(); const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) ); - return anElem != 0 ? anElem->GetType() != SMDSAbs_Face || anElem->NbNodes() == 3 : false; + return anElem && anElem->GetType() == SMDSAbs_Face && + ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6 : 3 )); } //======================================================================= @@ -301,14 +310,15 @@ bool SMESHGUI_TriangleFilter::IsObjValid( const int theObjId ) const if ( myActor == 0 ) return false; - SMESH_Actor* anActor = ( SMESH_Actor* )myActor; - if ( anActor->GetObject() == 0 ) + SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor ); + if ( !anActor || anActor->GetObject() == 0 ) return false; - + SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh(); const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId ); - return anElem != 0 ? anElem->GetType() != SMDSAbs_Face || anElem->NbNodes() == 3 : false; + return anElem && anElem->GetType() == SMDSAbs_Face && + ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6 : 3 )); } //======================================================================= @@ -318,7 +328,7 @@ bool SMESHGUI_TriangleFilter::IsObjValid( const int theObjId ) const //======================================================================= int SMESHGUI_TriangleFilter::GetId() const { - return SMESHGUI_TriaFilter; + return SMESH::TriaFilter; } //======================================================================= @@ -330,13 +340,155 @@ bool SMESHGUI_TriangleFilter::IsNodeFilter() const return false; } +/* + Class : SMESHGUI_FacesFilter + Description : Verify whether selected cell is any face +*/ + + +//======================================================================= +// name : SMESHGUI_FacesFilter::SMESHGUI_FacesFilter +// Purpose : Constructor +//======================================================================= +SMESHGUI_FacesFilter::SMESHGUI_FacesFilter() +: SMESHGUI_Filter() +{ +} + +SMESHGUI_FacesFilter::~SMESHGUI_FacesFilter() +{ +} + +//======================================================================= +// name : SMESHGUI_FacesFilter::IsValid +// Purpose : Verify whether selected cell is face +//======================================================================= +bool SMESHGUI_FacesFilter::IsValid( const int theCellId ) const +{ + if ( myActor == 0 ) + return false; + + SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor ); + if ( !anActor || anActor->GetObject() == 0 ) + return false; + + SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh(); + const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) ); + + return anElem && anElem->GetType() == SMDSAbs_Face; +} + +//======================================================================= +// name : SMESHGUI_FacesFilter::IsValid +// Purpose : Verify whether selected cell is face +//======================================================================= +bool SMESHGUI_FacesFilter::IsObjValid( const int theObjId ) const +{ + if ( myActor == 0 ) + return false; + + SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor ); + if ( !anActor || anActor->GetObject() == 0 ) + return false; + + SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh(); + const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId ); + + return anElem && anElem->GetType() == SMDSAbs_Face; +} + +//======================================================================= +// name : SMESHGUI_FacesFilter::GetId +// Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType +// enumeration. All filters must have different ids +//======================================================================= +int SMESHGUI_FacesFilter::GetId() const +{ + return SMESH::FaceFilter; +} + +//======================================================================= +// name : SMESHGUI_FacesFilter::IsNodeFilter +// Purpose : Returns true if filter is intended for nodes +//======================================================================= +bool SMESHGUI_FacesFilter::IsNodeFilter() const +{ + return false; +} + +/* + Class : SMESHGUI_VolumesFilter + Description : Verify whether selected cell is any volume +*/ +//======================================================================= +// name : SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter +// Purpose : Constructor +//======================================================================= +SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter() +: SMESHGUI_Filter() +{ +} +SMESHGUI_VolumesFilter::~SMESHGUI_VolumesFilter() +{ +} +//======================================================================= +// name : SMESHGUI_VolumesFilter::IsValid +// Purpose : Verify whether selected cell is volume +//======================================================================= +bool SMESHGUI_VolumesFilter::IsValid( const int theCellId ) const +{ + if ( myActor == 0 || theCellId < 1 ) + return false; + + SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor ); + if ( !anActor || anActor->GetObject() == 0 ) + return false; + + SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh(); + const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) ); + + return anElem && anElem->GetType() == SMDSAbs_Volume; +} +//======================================================================= +// name : SMESHGUI_VolumesFilter::IsValid +// Purpose : Verify whether selected cell is volume +//======================================================================= +bool SMESHGUI_VolumesFilter::IsObjValid( const int theObjId ) const +{ + if ( myActor == 0 ) + return false; + + SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor ); + if ( !anActor || anActor->GetObject() == 0 ) + return false; + SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh(); + const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId ); + return anElem && anElem->GetType() == SMDSAbs_Volume; +} +//======================================================================= +// name : SMESHGUI_VolumesFilter::GetId +// Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType +// enumeration. All filters must have different ids +//======================================================================= +int SMESHGUI_VolumesFilter::GetId() const +{ + return SMESH::VolumeFilter; +} +//======================================================================= +// name : SMESHGUI_VolumesFilter::IsNodeFilter +// Purpose : Returns true if filter is intended for nodes +//======================================================================= +bool SMESHGUI_VolumesFilter::IsNodeFilter() const +{ + return false; +}