Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/smesh.git] / src / SMESHFiltersSelection / SMESH_TypeFilter.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #include "SMESH_TypeFilter.hxx"
22
23 #include <SUIT_Session.h>
24
25 #include <SalomeApp_Study.h>
26 #include <LightApp_DataOwner.h>
27
28 #include <SALOMEconfig.h>
29 #include CORBA_CLIENT_HEADER(SMESH_Gen)
30
31 SMESH_TypeFilter::SMESH_TypeFilter (MeshObjectType theType)
32 {
33   myType = theType;
34 }
35
36 SMESH_TypeFilter::~SMESH_TypeFilter()
37 {
38 }
39
40 bool SMESH_TypeFilter::isOk (const SUIT_DataOwner* theDataOwner) const
41 {
42   bool Ok = false, extractReference = true;
43
44   const LightApp_DataOwner* owner =
45     dynamic_cast<const LightApp_DataOwner*>(theDataOwner);
46   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
47     (SUIT_Session::session()->activeApplication()->activeStudy());
48
49   if (owner && appStudy) {
50     _PTR(Study) study = appStudy->studyDS();
51     QString entry = owner->entry();
52
53     _PTR(SObject) obj (study->FindObjectID(entry.latin1())), aRefSO;
54     if( extractReference && obj && obj->ReferencedObject( aRefSO ) )
55       obj = aRefSO;
56     if (!obj) return false;
57
58     _PTR(SObject) objFather = obj->GetFather();
59     _PTR(SComponent) objComponent = obj->GetFatherComponent();
60
61     if( objComponent->ComponentDataType()!="SMESH" )
62       return false;
63
64     int aLevel = obj->Depth() - objComponent->Depth();
65
66     // Max level under the component is 5:
67     //
68     // 0    Mesh Component
69     // 1    |- Hypotheses
70     // 2    |  |- Regular 1D
71     //      |- Algorithms
72     //      |- Mesh 1
73     //         |- * Main Shape
74     //         |- Applied Hypotheses
75     //         |- Applied Algorithms
76     //         |- Submeshes on Face
77     // 3       |  |- SubmeshFace
78     // 4       |     |- * Face 1
79     // 4       |     |- Applied algorithms ( selectable in Use Case Browser )
80     // 5       |          |- Regular 1D
81     //         |- Group Of Nodes
82
83     if (aLevel <= 0)
84       return false;
85
86     switch (myType)
87     {
88       case HYPOTHESIS:
89         {
90           if      (aLevel == 2 && (objFather->Tag() == SMESH::Tag_HypothesisRoot))
91             // hypo definition
92             Ok = true;
93           else if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_RefOnAppliedHypothesis))
94             // applied global hypo
95             Ok = true;
96           else if (aLevel == 5 && (objFather->Tag() == SMESH::Tag_RefOnAppliedHypothesis))
97             // applied local hypo
98             Ok = true;
99           break;
100         }
101       case ALGORITHM:
102         {
103           if      (aLevel == 2 && (objFather->Tag() == SMESH::Tag_AlgorithmsRoot))
104             // algo definition
105             Ok = true;
106           else if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_RefOnAppliedAlgorithms))
107             // applied global algo
108             Ok = true;
109           else if (aLevel == 5 && (objFather->Tag() == SMESH::Tag_RefOnAppliedAlgorithms))
110             // applied local algo
111             Ok = true;
112           break;
113         }
114       case MESH:
115         {
116           if (aLevel == 1 && (obj->Tag() >= SMESH::Tag_FirstMeshRoot))
117             Ok = true;
118           break;
119         }
120       case SUBMESH:
121         {
122           // see SMESH_Gen_i.cxx for tag numbers
123           if (aLevel == 3 && (objFather->Tag() >= SMESH::Tag_FirstSubMesh &&
124                               objFather->Tag() <= SMESH::Tag_LastSubMesh))
125             Ok = true;
126           break;
127         }
128       case MESHorSUBMESH:
129         {
130           if (aLevel == 1 && (obj->Tag() >= SMESH::Tag_FirstMeshRoot))
131             Ok = true; // mesh
132           else if (aLevel == 3 && (objFather->Tag() >= SMESH::Tag_FirstSubMesh &&
133                                    objFather->Tag() <= SMESH::Tag_LastSubMesh))
134             Ok = true;
135           break;
136         }
137       case SUBMESH_VERTEX: // Label "SubMeshes on vertexes"
138         {
139           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnVertex))
140             Ok = true;
141           break;
142         }
143       case SUBMESH_EDGE:
144         {
145           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnEdge))
146             Ok = true;
147           break;
148         }
149       case SUBMESH_FACE:
150         {
151           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnFace))
152             Ok = true;
153           break;
154         }
155       case SUBMESH_SOLID:
156         {
157           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnSolid))
158             Ok = true;
159           break;
160         }
161       case SUBMESH_COMPOUND:
162         {
163           if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnCompound))
164             Ok = true;
165           break;
166         }
167       case GROUP:
168         {
169           if (aLevel == 3 && (objFather->Tag() >= SMESH::Tag_FirstGroup))
170             Ok = true;
171           break;
172         }
173     }
174   }
175   return Ok;
176 }
177
178 MeshObjectType SMESH_TypeFilter::type() const
179 {
180   return myType;
181 }