Salome HOME
Using files from package LightApp instead of SalomeApp
[modules/smesh.git] / src / SMESHFiltersSelection / SMESH_TypeFilter.cxx
index 9f17ae1b4e0f5d40ff6a9821af3ef69f10d2380b..f406022d264b4c852e47da78af1f6e5d218ae115 100644 (file)
@@ -1,74 +1,84 @@
-//  File      : SMESH_TypeFilter.cxx
-//  Created   : Fri Dec 07 09:57:24 2001
-//  Author    : Nicolas REJNERI
-//  Project   : SALOME
-//  Module    : SMESH
-//  Copyright : Open CASCADE
-//  $Header$
+#include "SMESH_TypeFilter.hxx"
 
 
-#include "SMESH_TypeFilter.ixx"
+#include <SUIT_Session.h>
 
 
-#include "SALOME_InteractiveObject.hxx"
-#include "SALOME_TypeFilter.hxx"
+#include <SalomeApp_Study.h>
+#include <LightApp_DataOwner.h>
 
 
-#include "utilities.h"
-#include "QAD_Application.h"
-#include "QAD_Desktop.h"
-#include "QAD_Study.h"
-
-using namespace std;
+SMESH_TypeFilter::SMESH_TypeFilter (MeshObjectType theType) 
+{
+  myType = theType;
+}
 
 
-SMESH_TypeFilter::SMESH_TypeFilter(MeshObjectType aType
+SMESH_TypeFilter::~SMESH_TypeFilter(
 {
 {
-  myKind = aType;
 }
 
 }
 
-Standard_Boolean SMESH_TypeFilter::IsOk(const Handle(SALOME_InteractiveObject)& anObj) const 
+bool SMESH_TypeFilter::isOk (const SUIT_DataOwner* theDataOwner) const
 {
 {
-  Handle(SALOME_TypeFilter) meshFilter = new SALOME_TypeFilter( "SMESH" );
-  if ( !meshFilter->IsOk(anObj) ) 
-    return false;
+  bool Ok = false, extractReference = true;
+
+  const LightApp_DataOwner* owner =
+    dynamic_cast<const LightApp_DataOwner*>(theDataOwner);
+  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
+    (SUIT_Session::session()->activeApplication()->activeStudy());
 
 
-  bool Ok = false;
+  if (owner && appStudy) {
+    _PTR(Study) study = appStudy->studyDS();
+    QString entry = owner->entry();
 
 
-  if ( anObj->hasEntry() ) {
-    QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
-    SALOMEDS::Study_var aStudy = ActiveStudy->getStudyDocument();
-    SALOMEDS::SObject_var obj = aStudy->FindObjectID( anObj->getEntry() );
+    _PTR(SObject) obj (study->FindObjectID(entry.latin1())), aRefSO;
+    if( extractReference && obj && obj->ReferencedObject( aRefSO ) )
+      obj = aRefSO;
+    if (!obj) return false;
+
+    _PTR(SObject) objFather = obj->GetFather();
+    _PTR(SComponent) objComponent = obj->GetFatherComponent();
+
+    if( objComponent->ComponentDataType()!="SMESH" )
+      return false;
 
 
-    SALOMEDS::SObject_var objFather = obj->GetFather();
-    SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
-    
     int aLevel = obj->Depth() - objComponent->Depth();
 
     int aLevel = obj->Depth() - objComponent->Depth();
 
-    // Max level under the component is 4:
+    // Max level under the component is 5:
     //
     // 0    Mesh Component
     // 1    |- Hypotheses
     // 2    |  |- Regular 1D
     //      |- Algorithms
     //      |- Mesh 1
     //
     // 0    Mesh Component
     // 1    |- Hypotheses
     // 2    |  |- Regular 1D
     //      |- Algorithms
     //      |- Mesh 1
+    //         |- * Main Shape
     //         |- Applied Hypotheses
     //         |- Applied Algorithms
     //         |- Submeshes on Face
     // 3       |  |- SubmeshFace
     //         |- Applied Hypotheses
     //         |- Applied Algorithms
     //         |- Submeshes on Face
     // 3       |  |- SubmeshFace
+    // 4       |     |- * Face 1
     // 4       |     |- Applied algorithms ( selectable in Use Case Browser )
     // 4       |     |- Applied algorithms ( selectable in Use Case Browser )
+    // 5       |          |- Regular 1D
     //         |- Group Of Nodes
 
     //         |- Group Of Nodes
 
-    if ( aLevel <= 0 )
+    if (aLevel <= 0)
       return false;
 
       return false;
 
-    switch ( myKind )
+    switch (myType)
       {
       case HYPOTHESIS:
        {
       {
       case HYPOTHESIS:
        {
-         if ( aLevel == 2 && ( objFather->Tag() == 1 ))
+         if ( aLevel == 2 && ( objFather->Tag() == 1 )) // hypo definition
+           Ok = true;
+         else if ( aLevel == 3 && ( objFather->Tag() == 2 )) // applied global hypo
+           Ok = true;
+         else if ( aLevel == 5 && ( objFather->Tag() == 2 )) // applied local hypo
            Ok = true;
          break;
        }
       case ALGORITHM:
        {
            Ok = true;
          break;
        }
       case ALGORITHM:
        {
-         if ( aLevel == 2 && ( objFather->Tag() == 2 ))
+         if ( aLevel == 2 && ( objFather->Tag() == 2 )) // algo definition
+           Ok = true;
+         else if ( aLevel == 3 && ( objFather->Tag() == 3 )) // applied global algo
+           Ok = true;
+         else if ( aLevel == 5 && ( objFather->Tag() == 3 )) // applied local algo
            Ok = true;
          break;
        }
            Ok = true;
          break;
        }
@@ -133,3 +143,8 @@ Standard_Boolean SMESH_TypeFilter::IsOk(const Handle(SALOME_InteractiveObject)&
   }
   return Ok;
 }
   }
   return Ok;
 }
+
+MeshObjectType SMESH_TypeFilter::type() const 
+{
+  return myType;
+}