Salome HOME
Fix wrong comments indentation
[modules/smesh.git] / src / SMESHFiltersSelection / SMESH_TypeFilter.cxx
index dd7de5e4d68d2d8ad1b1ddbce9186a11074671fc..9f17ae1b4e0f5d40ff6a9821af3ef69f10d2380b 100644 (file)
@@ -1,32 +1,11 @@
-//  SMESH SMESHFiltersSelection : filter selector for viewer
-//
-//  Copyright (C) 2003  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 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 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
-//
-//
-//
-//  File   : SMESH_TypeFilter.cxx
-//  Author : Nicolas REJNERI
-//  Module : SMESH
+//  File      : SMESH_TypeFilter.cxx
+//  Created   : Fri Dec 07 09:57:24 2001
+//  Author    : Nicolas REJNERI
+//  Project   : SALOME
+//  Module    : SMESH
+//  Copyright : Open CASCADE
 //  $Header$
 
-using namespace std;
 #include "SMESH_TypeFilter.ixx"
 
 #include "SALOME_InteractiveObject.hxx"
@@ -37,6 +16,7 @@ using namespace std;
 #include "QAD_Desktop.h"
 #include "QAD_Study.h"
 
+using namespace std;
 
 SMESH_TypeFilter::SMESH_TypeFilter(MeshObjectType aType) 
 {
@@ -45,115 +25,111 @@ SMESH_TypeFilter::SMESH_TypeFilter(MeshObjectType aType)
 
 Standard_Boolean SMESH_TypeFilter::IsOk(const Handle(SALOME_InteractiveObject)& anObj) const 
 {
-  Handle(SALOME_TypeFilter) meshFilter = new SALOME_TypeFilter( "MESH" );
+  Handle(SALOME_TypeFilter) meshFilter = new SALOME_TypeFilter( "SMESH" );
   if ( !meshFilter->IsOk(anObj) ) 
     return false;
 
+  bool Ok = false;
+
   if ( anObj->hasEntry() ) {
     QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
     SALOMEDS::Study_var aStudy = ActiveStudy->getStudyDocument();
     SALOMEDS::SObject_var obj = aStudy->FindObjectID( anObj->getEntry() );
 
-    bool Ok = false;
+    SALOMEDS::SObject_var objFather = obj->GetFather();
+    SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
+    
+    int aLevel = obj->Depth() - objComponent->Depth();
+
+    // Max level under the component is 4:
+    //
+    // 0    Mesh Component
+    // 1    |- Hypotheses
+    // 2    |  |- Regular 1D
+    //      |- Algorithms
+    //      |- Mesh 1
+    //         |- Applied Hypotheses
+    //         |- Applied Algorithms
+    //         |- Submeshes on Face
+    // 3       |  |- SubmeshFace
+    // 4       |     |- Applied algorithms ( selectable in Use Case Browser )
+    //         |- Group Of Nodes
+
+    if ( aLevel <= 0 )
+      return false;
 
     switch ( myKind )
       {
       case HYPOTHESIS:
        {
-         SALOMEDS::SObject_var objFather = obj->GetFather();
-         SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
-         if (( objFather->Tag() == 1 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) )
+         if ( aLevel == 2 && ( objFather->Tag() == 1 ))
            Ok = true;
          break;
        }
       case ALGORITHM:
        {
-         SALOMEDS::SObject_var objFather = obj->GetFather();
-         SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
-         if (( objFather->Tag() == 2 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) )
+         if ( aLevel == 2 && ( objFather->Tag() == 2 ))
            Ok = true;
          break;
        }
       case MESH:
        {
-         SALOMEDS::SObject_var objFather = obj->GetFather();
-         SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
-         
-         if (( obj->Tag() >= 3 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) == 0 ) )
+         if ( aLevel == 1 && ( obj->Tag() >= 3 ))
            Ok = true;
          break;
        }
       case SUBMESH:
        {
-         SALOMEDS::SObject_var objFather = obj->GetFather();
-         SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
-         
-         if (( objFather->Tag() >= 4 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) )
+         // see SMESH_Gen_i.cxx for tag numbers
+         if ( aLevel == 3 && ( objFather->Tag() >= 4 && objFather->Tag() <= 10 ))
            Ok = true;
          break;
        }
       case MESHorSUBMESH:
        {
-         SALOMEDS::SObject_var objFather = obj->GetFather();
-         SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
-         
-         if (( obj->Tag() >= 3 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) == 0 ) )
-           Ok = true;
-
-          if (( objFather->Tag() >= 4 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) )
+         if ( aLevel == 1 && ( obj->Tag() >= 3 ))
+           Ok = true; // mesh
+          else if ( aLevel == 3 && ( objFather->Tag() >= 4 && objFather->Tag() <= 10 ))
            Ok = true;
-
          break;
        }
-      case SUBMESH_VERTEX:
+      case SUBMESH_VERTEX:  // Label "SubMeshes on vertexes"
        {
-         SALOMEDS::SObject_var objFather = obj->GetFather();
-         SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
-         
-         if (( obj->Tag() == 4 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) && ( objFather->Tag() >= 3 ))
+         if ( aLevel == 3 && ( objFather->Tag() == 4 ))
            Ok = true;
          break;
        }
       case SUBMESH_EDGE:
        {
-         SALOMEDS::SObject_var objFather = obj->GetFather();
-         SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
-         
-         if (( obj->Tag() == 5 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) && ( objFather->Tag() >= 3 ))
+         if ( aLevel == 3 && ( objFather->Tag() == 5 ))
            Ok = true;
          break;
        }
       case SUBMESH_FACE:
        {
-         SALOMEDS::SObject_var objFather = obj->GetFather();
-         SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
-         
-         if (( obj->Tag() == 6 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) && ( objFather->Tag() >= 3 ))
+         if ( aLevel == 3 && ( objFather->Tag() == 7 ))
            Ok = true;
          break;
        }
       case SUBMESH_SOLID:
        {
-         SALOMEDS::SObject_var objFather = obj->GetFather();
-         SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
-         
-         if (( obj->Tag() == 7 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) && ( objFather->Tag() >= 3 ))
+         if ( aLevel == 3 && ( objFather->Tag() == 9 ))
            Ok = true;
          break;
        }
       case SUBMESH_COMPOUND:
        {
-         SALOMEDS::SObject_var objFather = obj->GetFather();
-         SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
-         
-         if (( obj->Tag() == 8 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) && ( objFather->Tag() >= 3 ))
+         if ( aLevel == 3 && ( objFather->Tag() == 10 ))
+           Ok = true;
+         break;
+       }
+      case GROUP:
+       {
+         if ( aLevel == 3 && ( objFather->Tag() > 10 ))
            Ok = true;
          break;
        }
       }
-
-    if ( Ok )
-      return true;
   }
-  return false;
+  return Ok;
 }