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