1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SMESH_TypeFilter.hxx"
25 #include <LightApp_DataOwner.h>
26 #include <SUIT_Session.h>
27 #include <SalomeApp_Application.h>
28 #include <SalomeApp_Study.h>
30 #include <SALOMEconfig.h>
31 #include CORBA_CLIENT_HEADER(SMESH_Gen)
33 SMESH_TypeFilter::SMESH_TypeFilter (SMESH::MeshObjectType theType)
38 SMESH_TypeFilter::~SMESH_TypeFilter()
44 //================================================================================
46 * \brief Returns true if \a obj is SMESH_IDSource including elements of a given \a type
48 //================================================================================
50 bool isIDSourceOfType( _PTR(SObject) obj, SMESH::ElementType type )
53 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
54 (SUIT_Session::session()->activeApplication());
55 _PTR(GenericAttribute) anAttr;
56 if ( obj->FindAttribute(anAttr, "AttributeIOR"))
58 _PTR(AttributeIOR) anIOR = anAttr;
59 std::string aVal = anIOR->Value();
60 if ( aVal.size() > 0 )
62 CORBA::Object_var corbaObj = app->orb()->string_to_object( aVal.c_str() );
63 SMESH::SMESH_IDSource_var ids = SMESH::SMESH_IDSource::_narrow( corbaObj );
64 if ( ! ids->_is_nil() )
66 SMESH::array_of_ElementType_var types = ids->GetTypes();
67 for ( int i = 0, nb = types->length(); i < nb && !Ok; ++i )
68 Ok = ( types[i] == type );
76 bool SMESH_TypeFilter::isOk (const SUIT_DataOwner* theDataOwner) const
78 bool Ok = false, extractReference = true;
80 const LightApp_DataOwner* owner =
81 dynamic_cast<const LightApp_DataOwner*>(theDataOwner);
82 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>
83 (SUIT_Session::session()->activeApplication()->activeStudy());
85 if (owner && appStudy) {
86 _PTR(Study) study = appStudy->studyDS();
87 QString entry = owner->entry();
89 _PTR(SObject) obj (study->FindObjectID(entry.toUtf8().data())), aRefSO;
90 if( extractReference && obj && obj->ReferencedObject( aRefSO ) )
92 if (!obj) return false;
94 _PTR(SObject) objFather = obj->GetFather();
95 _PTR(SComponent) objComponent = obj->GetFatherComponent();
97 if( objComponent->ComponentDataType()!="SMESH" )
100 int aLevel = obj->Depth() - objComponent->Depth();
102 // Max level under the component is 5:
110 // |- Applied Hypotheses
111 // |- Applied Algorithms
112 // |- Submeshes on Face
113 // 3 | |- SubmeshFace
115 // 4 | |- Applied algorithms ( selectable in Use Case Browser )
125 case SMESH::HYPOTHESIS:
127 if (aLevel == 2 && (objFather->Tag() == SMESH::Tag_HypothesisRoot))
130 else if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_RefOnAppliedHypothesis))
131 // applied global hypo
133 else if (aLevel == 5 && (objFather->Tag() == SMESH::Tag_RefOnAppliedHypothesis))
134 // applied local hypo
138 case SMESH::ALGORITHM:
140 if (aLevel == 2 && (objFather->Tag() == SMESH::Tag_AlgorithmsRoot))
143 else if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_RefOnAppliedAlgorithms))
144 // applied global algo
146 else if (aLevel == 5 && (objFather->Tag() == SMESH::Tag_RefOnAppliedAlgorithms))
147 // applied local algo
153 if (aLevel == 1 && (obj->Tag() >= SMESH::Tag_FirstMeshRoot))
159 // see SMESH_Gen_i.cxx for tag numbers
160 if (aLevel == 3 && (objFather->Tag() >= SMESH::Tag_FirstSubMesh &&
161 objFather->Tag() <= SMESH::Tag_LastSubMesh))
165 case SMESH::MESHorSUBMESH:
167 if (aLevel == 1 && (obj->Tag() >= SMESH::Tag_FirstMeshRoot))
169 else if (aLevel == 3 && (objFather->Tag() >= SMESH::Tag_FirstSubMesh &&
170 objFather->Tag() <= SMESH::Tag_LastSubMesh))
174 case SMESH::SUBMESH_VERTEX: // Label "SubMeshes on vertexes"
176 if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnVertex))
180 case SMESH::SUBMESH_EDGE:
182 if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnEdge))
186 case SMESH::SUBMESH_FACE:
188 if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnFace))
192 case SMESH::SUBMESH_SOLID:
194 if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnSolid))
198 case SMESH::SUBMESH_COMPOUND:
200 if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_SubMeshOnCompound))
206 if (aLevel == 3 && (objFather->Tag() >= SMESH::Tag_FirstGroup))
210 case SMESH::GROUP_NODE:
212 if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_NodeGroups))
216 case SMESH::GROUP_EDGE:
218 if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_EdgeGroups))
222 case SMESH::GROUP_FACE:
224 if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_FaceGroups))
228 case SMESH::GROUP_VOLUME:
230 if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_VolumeGroups))
234 case SMESH::GROUP_0D:
236 if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_0DElementsGroups))
240 case SMESH::GROUP_BALL:
242 if (aLevel == 3 && (objFather->Tag() == SMESH::Tag_BallElementsGroups))
246 case SMESH::IDSOURCE:
248 Ok = ( SMESH_TypeFilter(SMESH::MESHorSUBMESH).isOk( theDataOwner ) ||
249 SMESH_TypeFilter(SMESH::GROUP) .isOk( theDataOwner ));
252 case SMESH::IDSOURCE_EDGE:
254 Ok = isIDSourceOfType( obj, SMESH::EDGE );
257 case SMESH::IDSOURCE_FACE:
259 Ok = isIDSourceOfType( obj, SMESH::FACE );
262 case SMESH::IDSOURCE_VOLUME:
264 Ok = isIDSourceOfType( obj, SMESH::VOLUME );
273 SMESH::MeshObjectType SMESH_TypeFilter::type() const