Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / SMESHFiltersSelection / SMESH_TypeFilter.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "SMESH_TypeFilter.hxx"
23
24 #include <SUIT_Session.h>
25
26 #include <SalomeApp_Study.h>
27 #include <LightApp_DataOwner.h>
28
29 #include <SALOMEconfig.h>
30 #include CORBA_CLIENT_HEADER(SMESH_Gen)
31
32 SMESH_TypeFilter::SMESH_TypeFilter (MeshObjectType theType)
33 {
34   myType = theType;
35 }
36
37 SMESH_TypeFilter::~SMESH_TypeFilter()
38 {
39 }
40
41 bool SMESH_TypeFilter::isOk (const SUIT_DataOwner* theDataOwner) const
42 {
43   bool Ok = false, extractReference = true;
44
45   const LightApp_DataOwner* owner =
46     dynamic_cast<const LightApp_DataOwner*>(theDataOwner);
47   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
48     (SUIT_Session::session()->activeApplication()->activeStudy());
49
50   if (owner && appStudy) {
51     _PTR(Study) study = appStudy->studyDS();
52     QString entry = owner->entry();
53
54     _PTR(SObject) obj (study->FindObjectID(entry.toLatin1().data())), aRefSO;
55     if( extractReference && obj && obj->ReferencedObject( aRefSO ) )
56       obj = aRefSO;
57     if (!obj) return false;
58
59     _PTR(SObject) objFather = obj->GetFather();
60     _PTR(SComponent) objComponent = obj->GetFatherComponent();
61
62     if( objComponent->ComponentDataType()!="SMESH" )
63       return false;
64
65     int aLevel = obj->Depth() - objComponent->Depth();
66
67     // Max level under the component is 5:
68     //
69     // 0    Mesh Component
70     // 1    |- Hypotheses
71     // 2    |  |- Regular 1D
72     //      |- Algorithms
73     //      |- Mesh 1
74     //         |- * Main Shape
75     //         |- Applied Hypotheses
76     //         |- Applied Algorithms
77     //         |- Submeshes on Face
78     // 3       |  |- SubmeshFace
79     // 4       |     |- * Face 1
80     // 4       |     |- Applied algorithms ( selectable in Use Case Browser )
81     // 5       |          |- Regular 1D
82     //         |- Group Of Nodes
83
84     if (aLevel <= 0)
85       return false;
86
87     switch (myType)
88     {
89       case HYPOTHESIS:
90         {
91           if      (aLevel == 2 && (objFather->Tag() == SMESH::Tag_HypothesisRoot))
92             // hypo definition
93             Ok = true;
94           else if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_RefOnAppliedHypothesis))
95             // applied global hypo
96             Ok = true;
97           else if (aLevel == 5 && (objFather->Tag() == SMESH::Tag_RefOnAppliedHypothesis))
98             // applied local hypo
99             Ok = true;
100           break;
101         }
102       case ALGORITHM:
103         {
104           if      (aLevel == 2 && (objFather->Tag() == SMESH::Tag_AlgorithmsRoot))
105             // algo definition
106             Ok = true;
107           else if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_RefOnAppliedAlgorithms))
108             // applied global algo
109             Ok = true;
110           else if (aLevel == 5 && (objFather->Tag() == SMESH::Tag_RefOnAppliedAlgorithms))
111             // applied local algo
112             Ok = true;
113           break;
114         }
115       case MESH:
116         {
117           if (aLevel == 1 && (obj->Tag() >= SMESH::Tag_FirstMeshRoot))
118             Ok = true;
119           break;
120         }
121       case SUBMESH:
122         {
123           // see SMESH_Gen_i.cxx for tag numbers
124           if (aLevel == 3 && (objFather->Tag() >= SMESH::Tag_FirstSubMesh &&
125                               objFather->Tag() <= SMESH::Tag_LastSubMesh))
126             Ok = true;
127           break;
128         }
129       case MESHorSUBMESH:
130         {
131           if (aLevel == 1 && (obj->Tag() >= SMESH::Tag_FirstMeshRoot))
132             Ok = true; // mesh
133           else if (aLevel == 3 && (objFather->Tag() >= SMESH::Tag_FirstSubMesh &&
134                                    objFather->Tag() <= SMESH::Tag_LastSubMesh))
135             Ok = true;
136           break;
137         }
138       case SUBMESH_VERTEX: // Label "SubMeshes on vertexes"
139         {
140           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnVertex))
141             Ok = true;
142           break;
143         }
144       case SUBMESH_EDGE:
145         {
146           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnEdge))
147             Ok = true;
148           break;
149         }
150       case SUBMESH_FACE:
151         {
152           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnFace))
153             Ok = true;
154           break;
155         }
156       case SUBMESH_SOLID:
157         {
158           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnSolid))
159             Ok = true;
160           break;
161         }
162       case SUBMESH_COMPOUND:
163         {
164           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnCompound))
165             Ok = true;
166           break;
167         }
168       case GROUP:
169         {
170           if (aLevel == 3 && (objFather->Tag() >= SMESH::Tag_FirstGroup))
171             Ok = true;
172           break;
173         }
174     }
175   }
176   return Ok;
177 }
178
179 MeshObjectType SMESH_TypeFilter::type() const
180 {
181   return myType;
182 }