1 // SMESHGUI_Filter : Filters for VTK viewer
3 // Copyright (C) 2003 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.
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
22 // File : SMESHGUI_Filter.cxx
23 // Author : Sergey LITONIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_Filter.h"
29 #include "SMESHGUI_Utils.h"
31 #include <SMESH_Actor.h>
32 #include <SMDS_Mesh.hxx>
33 #include <SMDSAbs_ElementType.hxx>
35 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_Filter, VTKViewer_Filter)
36 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_Filter, VTKViewer_Filter)
38 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_PredicateFilter, SMESHGUI_Filter)
39 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_PredicateFilter, SMESHGUI_Filter)
41 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_QuadrangleFilter, SMESHGUI_Filter)
42 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_QuadrangleFilter, SMESHGUI_Filter)
44 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_TriangleFilter, SMESHGUI_Filter)
45 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_TriangleFilter, SMESHGUI_Filter)
47 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_FacesFilter, SMESHGUI_Filter)
48 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_FacesFilter, SMESHGUI_Filter)
50 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_VolumesFilter, SMESHGUI_Filter)
51 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_VolumesFilter, SMESHGUI_Filter)
54 Class : SMESHGUI_PredicateFilter
55 Description : Selection filter for VTK viewer. This class aggregate object
56 of SMESH_Predicate class and uses it for verification of criterion
59 //=======================================================================
60 // name : SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter
61 // Purpose : Constructor
62 //=======================================================================
63 SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter()
67 SMESHGUI_PredicateFilter::~SMESHGUI_PredicateFilter()
71 //=======================================================================
72 // name : SMESHGUI_PredicateFilter::IsValid
73 // Purpose : Verify whether entry id satisfies to criterion of the filter
74 //=======================================================================
75 bool SMESHGUI_PredicateFilter::IsValid( const int theCellId ) const
77 if ( myActor == 0 || myPred->_is_nil() )
80 SMESH_Actor* anActor = dynamic_cast<SMESH_Actor*>( myActor );
81 if ( !anActor || anActor->GetObject() == 0 )
84 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
85 SMESH::ElementType anElemType = myPred->GetElementType();
86 int aMeshId = anElemType == SMESH::NODE ? anActor->GetNodeObjId( theCellId )
87 : anActor->GetElemObjId( theCellId );
89 // if type of element != type of predicate return true because
90 // this predicate is not intended for filtering sush elements
91 const SMDS_MeshElement* anElem = anElemType == SMESH::NODE ? aMesh->FindNode( aMeshId )
92 : aMesh->FindElement( aMeshId );
93 if ( anElem != 0 && anElem->GetType() != (SMDSAbs_ElementType)myPred->GetElementType() )
96 return myPred->IsSatisfy( aMeshId );
99 //=======================================================================
100 // name : SMESHGUI_PredicateFilter::IsValid
101 // Purpose : Verify whether entry id satisfies to criterion of the filter
102 //=======================================================================
103 bool SMESHGUI_PredicateFilter::IsObjValid( const int theObjId ) const
105 if ( myActor == 0 || myPred->_is_nil() )
108 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
109 if ( anActor->GetObject() == 0 )
112 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
113 SMESH::ElementType anElemType = myPred->GetElementType();
115 // if type of element != type of predicate return true because
116 // this predicate is not intended for filtering sush elements
117 const SMDS_MeshElement* anElem = anElemType == SMESH::NODE ? aMesh->FindNode( theObjId )
118 : aMesh->FindElement( theObjId );
119 if ( anElem != 0 && anElem->GetType() != (SMDSAbs_ElementType)myPred->GetElementType() )
122 return myPred->IsSatisfy( theObjId );
125 //=======================================================================
126 // name : SMESHGUI_PredicateFilter::IsNodeFilter
127 // Purpose : Returns true if filter is intended for nodes
128 //=======================================================================
129 bool SMESHGUI_PredicateFilter::IsNodeFilter() const
131 return GetId() == SMESH::NodeFilter;
134 //=======================================================================
135 // name : SMESHGUI_PredicateFilter::SetPredicate
136 // Purpose : Set new pridicate to the filter
137 //=======================================================================
138 void SMESHGUI_PredicateFilter::SetPredicate( SMESH::Predicate_ptr thePred )
140 myPred = SMESH::Predicate::_duplicate( thePred );
143 //=======================================================================
144 // name : SMESHGUI_PredicateFilter::SetActor
145 // Purpose : Set new actor
146 //=======================================================================
147 void SMESHGUI_PredicateFilter::SetActor( SALOME_Actor* theActor )
149 if ( myActor == theActor )
151 SMESHGUI_Filter::SetActor( theActor );
153 if ( myActor != 0 && !myPred->_is_nil() )
155 SALOME_Actor* sActor = dynamic_cast<SALOME_Actor*>( myActor );
156 Handle(SALOME_InteractiveObject) anIO;
158 anIO = sActor->getIO();
159 if ( !anIO.IsNull() )
161 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
162 if(!aMesh->_is_nil())
163 myPred->SetMesh(aMesh);
168 //=======================================================================
169 // name : SMESHGUI_PredicateFilter::SetActor
170 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
171 // enumeration. All filters must have different ids
172 //=======================================================================
173 int SMESHGUI_PredicateFilter::GetId() const
175 if ( myPred->GetElementType() == SMESH::NODE ) return SMESH::NodeFilter;
176 else if ( myPred->GetElementType() == SMESH::EDGE ) return SMESH::EdgeFilter;
177 else if ( myPred->GetElementType() == SMESH::FACE ) return SMESH::FaceFilter;
178 else if ( myPred->GetElementType() == SMESH::VOLUME ) return SMESH::VolumeFilter;
179 else if ( myPred->GetElementType() == SMESH::ALL ) return SMESH::AllElementsFilter;
180 else return SMESH::UnknownFilter;
185 Class : SMESHGUI_QuadrangleFilter
186 Description : Verify whether selected cell is quadranle
189 //=======================================================================
190 // name : SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter
191 // Purpose : Constructor
192 //=======================================================================
193 SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter()
198 SMESHGUI_QuadrangleFilter::~SMESHGUI_QuadrangleFilter()
202 //=======================================================================
203 // name : SMESHGUI_QuadrangleFilter::IsValid
204 // Purpose : Verify whether selected cell is quadranle
205 //=======================================================================
206 bool SMESHGUI_QuadrangleFilter::IsValid( const int theCellId ) const
211 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
212 if ( anActor->GetObject() == 0 )
215 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
216 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
218 return anElem && anElem->GetType() == SMDSAbs_Face &&
219 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 ));
222 //=======================================================================
223 // name : SMESHGUI_QuadrangleFilter::IsValid
224 // Purpose : Verify whether selected cell is quadranle
225 //=======================================================================
226 bool SMESHGUI_QuadrangleFilter::IsObjValid( const int theObjId ) const
231 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
232 if ( anActor->GetObject() == 0 )
235 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
236 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
238 return anElem && anElem->GetType() == SMDSAbs_Face &&
239 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 ));
242 //=======================================================================
243 // name : SMESHGUI_QuadrangleFilter::SetActor
244 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
245 // enumeration. All filters must have different ids
246 //=======================================================================
247 int SMESHGUI_QuadrangleFilter::GetId() const
249 return SMESH::QuadFilter;
252 //=======================================================================
253 // name : SMESHGUI_QuadrangleFilter::IsNodeFilter
254 // Purpose : Returns true if filter is intended for nodes
255 //=======================================================================
256 bool SMESHGUI_QuadrangleFilter::IsNodeFilter() const
263 Class : SMESHGUI_TriangleFilter
264 Description : Verify whether selected cell is triangle
268 //=======================================================================
269 // name : SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter
270 // Purpose : Constructor
271 //=======================================================================
272 SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter()
277 SMESHGUI_TriangleFilter::~SMESHGUI_TriangleFilter()
281 //=======================================================================
282 // name : SMESHGUI_TriangleFilter::IsValid
283 // Purpose : Verify whether selected cell is triangle
284 //=======================================================================
285 bool SMESHGUI_TriangleFilter::IsValid( const int theCellId ) const
290 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
291 if ( anActor->GetObject() == 0 )
294 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
295 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
297 return anElem && anElem->GetType() == SMDSAbs_Face &&
298 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6 : 3 ));
301 //=======================================================================
302 // name : SMESHGUI_TriangleFilter::IsValid
303 // Purpose : Verify whether selected cell is triangle
304 //=======================================================================
305 bool SMESHGUI_TriangleFilter::IsObjValid( const int theObjId ) const
310 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
311 if ( anActor->GetObject() == 0 )
314 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
315 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
317 return anElem && anElem->GetType() == SMDSAbs_Face &&
318 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6 : 3 ));
321 //=======================================================================
322 // name : SMESHGUI_TriangleFilter::SetActor
323 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
324 // enumeration. All filters must have different ids
325 //=======================================================================
326 int SMESHGUI_TriangleFilter::GetId() const
328 return SMESH::TriaFilter;
331 //=======================================================================
332 // name : SMESHGUI_TriangleFilter::IsNodeFilter
333 // Purpose : Returns true if filter is intended for nodes
334 //=======================================================================
335 bool SMESHGUI_TriangleFilter::IsNodeFilter() const
341 Class : SMESHGUI_FacesFilter
342 Description : Verify whether selected cell is any face
346 //=======================================================================
347 // name : SMESHGUI_FacesFilter::SMESHGUI_FacesFilter
348 // Purpose : Constructor
349 //=======================================================================
350 SMESHGUI_FacesFilter::SMESHGUI_FacesFilter()
355 SMESHGUI_FacesFilter::~SMESHGUI_FacesFilter()
359 //=======================================================================
360 // name : SMESHGUI_FacesFilter::IsValid
361 // Purpose : Verify whether selected cell is face
362 //=======================================================================
363 bool SMESHGUI_FacesFilter::IsValid( const int theCellId ) const
368 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
369 if ( anActor->GetObject() == 0 )
372 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
373 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
375 return anElem && anElem->GetType() == SMDSAbs_Face;
378 //=======================================================================
379 // name : SMESHGUI_FacesFilter::IsValid
380 // Purpose : Verify whether selected cell is face
381 //=======================================================================
382 bool SMESHGUI_FacesFilter::IsObjValid( const int theObjId ) const
387 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
388 if ( anActor->GetObject() == 0 )
391 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
392 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
394 return anElem && anElem->GetType() == SMDSAbs_Face;
397 //=======================================================================
398 // name : SMESHGUI_FacesFilter::GetId
399 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
400 // enumeration. All filters must have different ids
401 //=======================================================================
402 int SMESHGUI_FacesFilter::GetId() const
404 return SMESH::FaceFilter;
407 //=======================================================================
408 // name : SMESHGUI_FacesFilter::IsNodeFilter
409 // Purpose : Returns true if filter is intended for nodes
410 //=======================================================================
411 bool SMESHGUI_FacesFilter::IsNodeFilter() const
418 Class : SMESHGUI_VolumesFilter
419 Description : Verify whether selected cell is any volume
423 //=======================================================================
424 // name : SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter
425 // Purpose : Constructor
426 //=======================================================================
427 SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter()
432 SMESHGUI_VolumesFilter::~SMESHGUI_VolumesFilter()
436 //=======================================================================
437 // name : SMESHGUI_VolumesFilter::IsValid
438 // Purpose : Verify whether selected cell is volume
439 //=======================================================================
440 bool SMESHGUI_VolumesFilter::IsValid( const int theCellId ) const
445 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
446 if ( anActor->GetObject() == 0 )
449 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
450 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
452 return anElem && anElem->GetType() == SMDSAbs_Volume;
455 //=======================================================================
456 // name : SMESHGUI_VolumesFilter::IsValid
457 // Purpose : Verify whether selected cell is volume
458 //=======================================================================
459 bool SMESHGUI_VolumesFilter::IsObjValid( const int theObjId ) const
464 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
465 if ( anActor->GetObject() == 0 )
468 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
469 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
471 return anElem && anElem->GetType() == SMDSAbs_Volume;
474 //=======================================================================
475 // name : SMESHGUI_VolumesFilter::GetId
476 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
477 // enumeration. All filters must have different ids
478 //=======================================================================
479 int SMESHGUI_VolumesFilter::GetId() const
481 return SMESH::VolumeFilter;
484 //=======================================================================
485 // name : SMESHGUI_VolumesFilter::IsNodeFilter
486 // Purpose : Returns true if filter is intended for nodes
487 //=======================================================================
488 bool SMESHGUI_VolumesFilter::IsNodeFilter() const