Salome HOME
23032: EDF SMESH: Projection 1D-2D fails with Netgen 1D-2D
[modules/smesh.git] / src / SMESHFiltersSelection / SMESH_TypeFilter.cxx
index ea3593b884f6453d606a9328597ce74f546a4fa0..5f12c7faa9a794c7b6757d6d6193cd8136be1b1d 100644 (file)
 
 #include "SMESH_TypeFilter.hxx"
 
+#include <LightApp_DataOwner.h>
 #include <SUIT_Session.h>
-
+#include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
-#include <LightApp_DataOwner.h>
 
 #include <SALOMEconfig.h>
 #include CORBA_CLIENT_HEADER(SMESH_Gen)
@@ -39,6 +39,40 @@ SMESH_TypeFilter::~SMESH_TypeFilter()
 {
 }
 
+namespace
+{
+  //================================================================================
+  /*!
+   * \brief Returns true if \a obj is SMESH_IDSource including elements of a given \a type 
+   */
+  //================================================================================
+
+  bool isIDSourceOfType( _PTR(SObject) obj, SMESH::ElementType type )
+  {
+    bool Ok = false;
+    SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
+      (SUIT_Session::session()->activeApplication());
+    _PTR(GenericAttribute) anAttr;
+    if ( obj->FindAttribute(anAttr, "AttributeIOR"))
+    {
+      _PTR(AttributeIOR) anIOR = anAttr;
+      std::string aVal = anIOR->Value();
+      if ( aVal.size() > 0 )
+      {
+        CORBA::Object_var corbaObj = app->orb()->string_to_object( aVal.c_str() );
+        SMESH::SMESH_IDSource_var ids = SMESH::SMESH_IDSource::_narrow( corbaObj );
+        if ( ! ids->_is_nil() )
+        {
+          SMESH::array_of_ElementType_var types = ids->GetTypes();
+          for ( int i = 0, nb = types->length(); i < nb && !Ok; ++i )
+            Ok = ( types[i] == type );
+        }
+      }
+    }
+    return Ok;
+  }
+}
+
 bool SMESH_TypeFilter::isOk (const SUIT_DataOwner* theDataOwner) const
 {
   bool Ok = false, extractReference = true;
@@ -215,6 +249,21 @@ bool SMESH_TypeFilter::isOk (const SUIT_DataOwner* theDataOwner) const
                  SMESH_TypeFilter(SMESH::GROUP)        .isOk( theDataOwner ));
           break;
         }
+      case SMESH::IDSOURCE_EDGE:
+        {
+          Ok = isIDSourceOfType( obj, SMESH::EDGE );
+          break;
+        }
+      case SMESH::IDSOURCE_FACE:
+        {
+          Ok = isIDSourceOfType( obj, SMESH::FACE );
+          break;
+        }
+      case SMESH::IDSOURCE_VOLUME:
+        {
+          Ok = isIDSourceOfType( obj, SMESH::VOLUME );
+          break;
+        }
     }
   }
   return Ok;