Salome HOME
Merge branch V7_3_1_BR
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Filter.cxx
index bb0905239283794ed4a8653242faa66a35d5a5b4..a6daed8fc8d89f0186cb4767e585adb6e7c49af4 100755 (executable)
@@ -1,46 +1,37 @@
-//  SMESHGUI_PredicateFilter : Filters for VTK viewer
+// Copyright (C) 2007-2014  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, 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.
+// 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.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.h"
 #include "SMESHGUI_Utils.h"
 
-#include "SMESH_Actor.h"
-#include "SMDS_Mesh.hxx"
-#include "SMDS_MeshElement.hxx"
-#include "SMDSAbs_ElementType.hxx"
-
-// OCCT Includes
-#include <gp_Vec.hxx>
-#include <Precision.hxx>
-
-// VTK Includes
-#include <vtkCell.h>
+#include <SMESH_Actor.h>
+#include <SMDS_Mesh.hxx>
+#include <SMDSAbs_ElementType.hxx>
 
 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_Filter, VTKViewer_Filter)
 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_Filter, VTKViewer_Filter)
@@ -60,6 +51,9 @@ IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_FacesFilter, SMESHGUI_Filter)
 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_VolumesFilter, SMESHGUI_Filter)
 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_VolumesFilter, SMESHGUI_Filter)
 
+IMPLEMENT_STANDARD_HANDLE(SMESHGUI_VolumeShapeFilter, SMESHGUI_Filter)
+IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_VolumeShapeFilter, SMESHGUI_Filter)
+
 /*
   Class       : SMESHGUI_PredicateFilter
   Description : Selection filter for VTK viewer. This class aggregate object
@@ -92,17 +86,18 @@ bool SMESHGUI_PredicateFilter::IsValid( const int theCellId ) const
     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 );
 }
 
@@ -115,19 +110,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 );
 }
@@ -138,7 +134,7 @@ bool SMESHGUI_PredicateFilter::IsObjValid( const int theObjId ) const
 //=======================================================================
 bool SMESHGUI_PredicateFilter::IsNodeFilter() const
 {
-  return GetId() == SMESHGUI_NodeFilter;
+  return GetId() == SMESH::NodeFilter;
 }
 
 //=======================================================================
@@ -182,12 +178,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;
 }
 
 
@@ -218,8 +214,8 @@ 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();
@@ -238,8 +234,8 @@ 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();
@@ -256,7 +252,7 @@ bool SMESHGUI_QuadrangleFilter::IsObjValid( const int theObjId ) const
 //=======================================================================
 int SMESHGUI_QuadrangleFilter::GetId() const
 {
-  return SMESHGUI_QuadFilter;
+  return SMESH::QuadFilter;
 }
 
 //=======================================================================
@@ -297,8 +293,8 @@ 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();
@@ -317,8 +313,8 @@ 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();
@@ -335,7 +331,7 @@ bool SMESHGUI_TriangleFilter::IsObjValid( const int theObjId ) const
 //=======================================================================
 int SMESHGUI_TriangleFilter::GetId() const
 {
-  return SMESHGUI_TriaFilter;
+  return SMESH::TriaFilter;
 }
 
 //=======================================================================
@@ -375,8 +371,8 @@ bool SMESHGUI_FacesFilter::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();
@@ -394,8 +390,8 @@ bool SMESHGUI_FacesFilter::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();
@@ -411,7 +407,7 @@ bool SMESHGUI_FacesFilter::IsObjValid( const int theObjId ) const
 //=======================================================================
 int SMESHGUI_FacesFilter::GetId() const
 {
-  return SMESHGUI_FaceFilter;
+  return SMESH::FaceFilter;
 }
 
 //=======================================================================
@@ -449,11 +445,11 @@ SMESHGUI_VolumesFilter::~SMESHGUI_VolumesFilter()
 //=======================================================================
 bool SMESHGUI_VolumesFilter::IsValid( const int theCellId ) const
 {
-  if ( myActor == 0 )
+  if ( myActor == 0 || theCellId < 1 )
     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();
@@ -471,8 +467,8 @@ bool SMESHGUI_VolumesFilter::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();
@@ -488,7 +484,7 @@ bool SMESHGUI_VolumesFilter::IsObjValid( const int theObjId ) const
 //=======================================================================
 int SMESHGUI_VolumesFilter::GetId() const
 {
-  return SMESHGUI_VolumeFilter;
+  return SMESH::VolumeFilter;
 }
 
 //=======================================================================
@@ -499,3 +495,86 @@ bool SMESHGUI_VolumesFilter::IsNodeFilter() const
 {
   return false;
 }
+
+
+/*
+  Class       : SMESHGUI_VolumeShapeFilter
+  Description : Verify whether selected cell is a volume of a certain shape
+*/
+
+
+//=======================================================================
+// name    : SMESHGUI_VolumeShapeFilter::SMESHGUI_VolumeShapeFilter
+// Purpose : Constructor
+//=======================================================================
+SMESHGUI_VolumeShapeFilter::SMESHGUI_VolumeShapeFilter(const SMDSAbs_GeometryType shape)
+  : SMESHGUI_Filter(), myGeometryType( shape )
+{
+}
+
+//=======================================================================
+// name    : SMESHGUI_VolumeShapeFilter::IsValid
+// Purpose : Verify whether selected cell is a volume of a certain shape
+//=======================================================================
+bool SMESHGUI_VolumeShapeFilter::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->GetGeomType() == myGeometryType;
+}
+
+//=======================================================================
+// name    : SMESHGUI_VolumeShapeFilter::IsValid
+// Purpose : Verify whether selected cell is volume
+//=======================================================================
+bool SMESHGUI_VolumeShapeFilter::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->GetGeomType() == myGeometryType;
+}
+
+//=======================================================================
+// name    : SMESHGUI_VolumeShapeFilter::GetId
+// Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
+//           enumeration. All filters must have different ids
+//=======================================================================
+int SMESHGUI_VolumeShapeFilter::GetId() const
+{
+  return GetId( myGeometryType );
+}
+
+//=======================================================================
+//function : GetId
+//purpose  : Compose filter ID basing on 
+//=======================================================================
+
+int SMESHGUI_VolumeShapeFilter::GetId( SMDSAbs_GeometryType shape )
+{
+  return SMESH::FirstGeometryTypeFilter + shape;
+}
+
+//=======================================================================
+// name    : SMESHGUI_VolumeShapeFilter::IsNodeFilter
+// Purpose : Returns true if filter is intended for nodes
+//=======================================================================
+bool SMESHGUI_VolumeShapeFilter::IsNodeFilter() const
+{
+  return false;
+}