Salome HOME
PAL14419 (IMP: a filter predicate to find nodes/elements lying on any
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Filter.cxx
index 08da7c92330c2b71942d566e0d7161b7ed55b567..bb0905239283794ed4a8653242faa66a35d5a5b4 100755 (executable)
@@ -17,7 +17,7 @@
 //  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
 //
 //
 //
 //  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)
@@ -83,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 )
@@ -98,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 );
 }
 
@@ -114,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 )
@@ -158,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);
@@ -214,11 +221,12 @@ 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 && anElem->GetType() == SMDSAbs_Face && anElem->NbNodes() == 4;
+
+  return anElem && anElem->GetType() == SMDSAbs_Face &&
+    ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 ));
 }
 
 //=======================================================================
@@ -233,11 +241,12 @@ 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 && anElem->GetType() == SMDSAbs_Face && anElem->NbNodes() == 4;
+  return anElem && anElem->GetType() == SMDSAbs_Face &&
+    ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8  : 4 ));
 }
 
 //=======================================================================
@@ -291,11 +300,12 @@ 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 && anElem->GetType() == SMDSAbs_Face && anElem->NbNodes() == 3;
+  return anElem && anElem->GetType() == SMDSAbs_Face &&
+    ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6  : 3 ));
 }
 
 //=======================================================================
@@ -310,11 +320,12 @@ 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 && anElem->GetType() == SMDSAbs_Face && anElem->NbNodes() == 3;
+  return anElem && anElem->GetType() == SMDSAbs_Face &&
+    ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6  : 3 ));
 }
 
 //=======================================================================
@@ -367,7 +378,7 @@ bool SMESHGUI_FacesFilter::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 ) );
 
@@ -386,7 +397,7 @@ bool SMESHGUI_FacesFilter::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 );
 
@@ -444,7 +455,7 @@ bool SMESHGUI_VolumesFilter::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 ) );
 
@@ -463,7 +474,7 @@ bool SMESHGUI_VolumesFilter::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 );
 
@@ -488,14 +499,3 @@ bool SMESHGUI_VolumesFilter::IsNodeFilter() const
 {
   return false;
 }
-
-
-
-
-
-
-
-
-
-
-