Salome HOME
dd7de5e4d68d2d8ad1b1ddbce9186a11074671fc
[modules/smesh.git] / src / SMESHFiltersSelection / SMESH_TypeFilter.cxx
1 //  SMESH SMESHFiltersSelection : filter selector for viewer
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESH_TypeFilter.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESH_TypeFilter.ixx"
31
32 #include "SALOME_InteractiveObject.hxx"
33 #include "SALOME_TypeFilter.hxx"
34
35 #include "utilities.h"
36 #include "QAD_Application.h"
37 #include "QAD_Desktop.h"
38 #include "QAD_Study.h"
39
40
41 SMESH_TypeFilter::SMESH_TypeFilter(MeshObjectType aType) 
42 {
43   myKind = aType;
44 }
45
46 Standard_Boolean SMESH_TypeFilter::IsOk(const Handle(SALOME_InteractiveObject)& anObj) const 
47 {
48   Handle(SALOME_TypeFilter) meshFilter = new SALOME_TypeFilter( "MESH" );
49   if ( !meshFilter->IsOk(anObj) ) 
50     return false;
51
52   if ( anObj->hasEntry() ) {
53     QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
54     SALOMEDS::Study_var aStudy = ActiveStudy->getStudyDocument();
55     SALOMEDS::SObject_var obj = aStudy->FindObjectID( anObj->getEntry() );
56
57     bool Ok = false;
58
59     switch ( myKind )
60       {
61       case HYPOTHESIS:
62         {
63           SALOMEDS::SObject_var objFather = obj->GetFather();
64           SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
65           if (( objFather->Tag() == 1 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) )
66             Ok = true;
67           break;
68         }
69       case ALGORITHM:
70         {
71           SALOMEDS::SObject_var objFather = obj->GetFather();
72           SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
73           if (( objFather->Tag() == 2 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) )
74             Ok = true;
75           break;
76         }
77       case MESH:
78         {
79           SALOMEDS::SObject_var objFather = obj->GetFather();
80           SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
81           
82           if (( obj->Tag() >= 3 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) == 0 ) )
83             Ok = true;
84           break;
85         }
86       case SUBMESH:
87         {
88           SALOMEDS::SObject_var objFather = obj->GetFather();
89           SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
90           
91           if (( objFather->Tag() >= 4 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) )
92             Ok = true;
93           break;
94         }
95       case MESHorSUBMESH:
96         {
97           SALOMEDS::SObject_var objFather = obj->GetFather();
98           SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
99           
100           if (( obj->Tag() >= 3 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) == 0 ) )
101             Ok = true;
102
103            if (( objFather->Tag() >= 4 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) )
104             Ok = true;
105
106           break;
107         }
108       case SUBMESH_VERTEX:
109         {
110           SALOMEDS::SObject_var objFather = obj->GetFather();
111           SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
112           
113           if (( obj->Tag() == 4 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) && ( objFather->Tag() >= 3 ))
114             Ok = true;
115           break;
116         }
117       case SUBMESH_EDGE:
118         {
119           SALOMEDS::SObject_var objFather = obj->GetFather();
120           SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
121           
122           if (( obj->Tag() == 5 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) && ( objFather->Tag() >= 3 ))
123             Ok = true;
124           break;
125         }
126       case SUBMESH_FACE:
127         {
128           SALOMEDS::SObject_var objFather = obj->GetFather();
129           SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
130           
131           if (( obj->Tag() == 6 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) && ( objFather->Tag() >= 3 ))
132             Ok = true;
133           break;
134         }
135       case SUBMESH_SOLID:
136         {
137           SALOMEDS::SObject_var objFather = obj->GetFather();
138           SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
139           
140           if (( obj->Tag() == 7 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) && ( objFather->Tag() >= 3 ))
141             Ok = true;
142           break;
143         }
144       case SUBMESH_COMPOUND:
145         {
146           SALOMEDS::SObject_var objFather = obj->GetFather();
147           SALOMEDS::SComponent_var objComponent = obj->GetFatherComponent();
148           
149           if (( obj->Tag() == 8 ) && (strcmp( objFather->GetID(), objComponent->GetID() ) != 0 ) && ( objFather->Tag() >= 3 ))
150             Ok = true;
151           break;
152         }
153       }
154
155     if ( Ok )
156       return true;
157   }
158   return false;
159 }