Salome HOME
Preferences-Mesh-General tab: regressions and reorganization.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Filter.cxx
index f6c4ae5b5f4b0e0a90ceff2839f3e6d3725db5ad..19b3fcb1ab62d0a354d550b888be0701a19603a0 100755 (executable)
 //  Module : SMESH
 
 #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"
 
-#include <vtkCell.h>
-
+// OCCT Includes
 #include <gp_Vec.hxx>
 #include <Precision.hxx>
-#include "SMESH_Actor.h"
-#include "SMESHGUI.h"
+
+// VTK Includes
+#include <vtkCell.h>
 
 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_Filter, VTKViewer_Filter)
 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_Filter, VTKViewer_Filter)
@@ -50,6 +54,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,10 +87,10 @@ 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<SMESH_Actor*>( 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 )
@@ -92,7 +102,7 @@ bool SMESHGUI_PredicateFilter::IsValid( const int theCellId ) const
                                                              : aMesh->FindElement( aMeshId );
   if ( anElem != 0 && anElem->GetType() != (SMDSAbs_ElementType)myPred->GetElementType() )
     return true;
-  
+
   return myPred->IsSatisfy( aMeshId );
 }
 
@@ -108,10 +118,10 @@ bool SMESHGUI_PredicateFilter::IsObjValid( const int theObjId ) const
   SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
   if ( anActor->GetObject() == 0 )
     return false;
-  
+
   SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
   SMESH::ElementType anElemType = 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 )
@@ -152,7 +162,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<SALOME_Actor*>( myActor );
+    Handle(SALOME_InteractiveObject) anIO;
+    if( sActor )
+      anIO = sActor->getIO();
     if ( !anIO.IsNull() )
     {
       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
@@ -208,11 +221,11 @@ bool SMESHGUI_QuadrangleFilter::IsValid( const int theCellId ) const
   SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
   if ( 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() == 4;
 }
 
 //=======================================================================
@@ -227,11 +240,11 @@ bool SMESHGUI_QuadrangleFilter::IsObjValid( const int theObjId ) const
   SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
   if ( 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() == 4;
 }
 
 //=======================================================================
@@ -285,11 +298,11 @@ bool SMESHGUI_TriangleFilter::IsValid( const int theCellId ) const
   SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
   if ( 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() == 3;
 }
 
 //=======================================================================
@@ -304,11 +317,11 @@ bool SMESHGUI_TriangleFilter::IsObjValid( const int theObjId ) const
   SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
   if ( 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() == 3;
 }
 
 //=======================================================================
@@ -330,13 +343,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 = ( SMESH_Actor* )myActor;
+  if ( 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 = ( SMESH_Actor* )myActor;
+  if ( 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 SMESHGUI_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 )
+    return false;
+
+  SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
+  if ( 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 = ( SMESH_Actor* )myActor;
+  if ( 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 SMESHGUI_VolumeFilter;
+}
+
+//=======================================================================
+// name    : SMESHGUI_VolumesFilter::IsNodeFilter
+// Purpose : Returns true if filter is intended for nodes
+//=======================================================================
+bool SMESHGUI_VolumesFilter::IsNodeFilter() const
+{
+  return false;
+}