1 // SMESHGUI_PredicateFilter : 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
24 // File : SMESHGUI_Filter.cxx
25 // Author : Sergey LITONIN
28 #include "SMESHGUI_Filter.h"
31 #include "SMESHGUI_Utils.h"
33 #include "SMESH_Actor.h"
34 #include "SMDS_Mesh.hxx"
35 #include "SMDS_MeshElement.hxx"
36 #include "SMDSAbs_ElementType.hxx"
40 #include <Precision.hxx>
45 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_Filter, VTKViewer_Filter)
46 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_Filter, VTKViewer_Filter)
48 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_PredicateFilter, SMESHGUI_Filter)
49 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_PredicateFilter, SMESHGUI_Filter)
51 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_QuadrangleFilter, SMESHGUI_Filter)
52 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_QuadrangleFilter, SMESHGUI_Filter)
54 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_TriangleFilter, SMESHGUI_Filter)
55 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_TriangleFilter, SMESHGUI_Filter)
57 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_FacesFilter, SMESHGUI_Filter)
58 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_FacesFilter, SMESHGUI_Filter)
60 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_VolumesFilter, SMESHGUI_Filter)
61 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_VolumesFilter, SMESHGUI_Filter)
64 Class : SMESHGUI_PredicateFilter
65 Description : Selection filter for VTK viewer. This class aggregate object
66 of SMESH_Predicate class and uses it for verification of criterion
69 //=======================================================================
70 // name : SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter
71 // Purpose : Constructor
72 //=======================================================================
73 SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter()
77 SMESHGUI_PredicateFilter::~SMESHGUI_PredicateFilter()
81 //=======================================================================
82 // name : SMESHGUI_PredicateFilter::IsValid
83 // Purpose : Verify whether entry id satisfies to criterion of the filter
84 //=======================================================================
85 bool SMESHGUI_PredicateFilter::IsValid( const int theCellId ) const
87 if ( myActor == 0 || myPred->_is_nil() )
90 SMESH_Actor* anActor = dynamic_cast<SMESH_Actor*>( myActor );
91 if ( !anActor || anActor->GetObject() == 0 )
94 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
95 SMESH::ElementType anElemType = myPred->GetElementType();
96 int aMeshId = anElemType == SMESH::NODE ? anActor->GetNodeObjId( theCellId )
97 : anActor->GetElemObjId( theCellId );
99 // if type of element != type of predicate return true because
100 // this predicate is not intended for filtering sush elements
101 const SMDS_MeshElement* anElem = anElemType == SMESH::NODE ? aMesh->FindNode( aMeshId )
102 : aMesh->FindElement( aMeshId );
103 if ( anElem != 0 && anElem->GetType() != (SMDSAbs_ElementType)myPred->GetElementType() )
106 return myPred->IsSatisfy( aMeshId );
109 //=======================================================================
110 // name : SMESHGUI_PredicateFilter::IsValid
111 // Purpose : Verify whether entry id satisfies to criterion of the filter
112 //=======================================================================
113 bool SMESHGUI_PredicateFilter::IsObjValid( const int theObjId ) const
115 if ( myActor == 0 || myPred->_is_nil() )
118 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
119 if ( anActor->GetObject() == 0 )
122 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
123 SMESH::ElementType anElemType = myPred->GetElementType();
125 // if type of element != type of predicate return true because
126 // this predicate is not intended for filtering sush elements
127 const SMDS_MeshElement* anElem = anElemType == SMESH::NODE ? aMesh->FindNode( theObjId )
128 : aMesh->FindElement( theObjId );
129 if ( anElem != 0 && anElem->GetType() != (SMDSAbs_ElementType)myPred->GetElementType() )
132 return myPred->IsSatisfy( theObjId );
135 //=======================================================================
136 // name : SMESHGUI_PredicateFilter::IsNodeFilter
137 // Purpose : Returns true if filter is intended for nodes
138 //=======================================================================
139 bool SMESHGUI_PredicateFilter::IsNodeFilter() const
141 return GetId() == SMESHGUI_NodeFilter;
144 //=======================================================================
145 // name : SMESHGUI_PredicateFilter::SetPredicate
146 // Purpose : Set new pridicate to the filter
147 //=======================================================================
148 void SMESHGUI_PredicateFilter::SetPredicate( SMESH::Predicate_ptr thePred )
150 myPred = SMESH::Predicate::_duplicate( thePred );
153 //=======================================================================
154 // name : SMESHGUI_PredicateFilter::SetActor
155 // Purpose : Set new actor
156 //=======================================================================
157 void SMESHGUI_PredicateFilter::SetActor( SALOME_Actor* theActor )
159 if ( myActor == theActor )
161 SMESHGUI_Filter::SetActor( theActor );
163 if ( myActor != 0 && !myPred->_is_nil() )
165 SALOME_Actor* sActor = dynamic_cast<SALOME_Actor*>( myActor );
166 Handle(SALOME_InteractiveObject) anIO;
168 anIO = sActor->getIO();
169 if ( !anIO.IsNull() )
171 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
172 if(!aMesh->_is_nil())
173 myPred->SetMesh(aMesh);
178 //=======================================================================
179 // name : SMESHGUI_PredicateFilter::SetActor
180 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
181 // enumeration. All filters must have different ids
182 //=======================================================================
183 int SMESHGUI_PredicateFilter::GetId() const
185 if ( myPred->GetElementType() == SMESH::NODE ) return SMESHGUI_NodeFilter;
186 else if ( myPred->GetElementType() == SMESH::EDGE ) return SMESHGUI_EdgeFilter;
187 else if ( myPred->GetElementType() == SMESH::FACE ) return SMESHGUI_FaceFilter;
188 else if ( myPred->GetElementType() == SMESH::VOLUME ) return SMESHGUI_VolumeFilter;
189 else if ( myPred->GetElementType() == SMESH::ALL ) return SMESHGUI_AllElementsFilter;
190 else return SMESHGUI_UnknownFilter;
195 Class : SMESHGUI_QuadrangleFilter
196 Description : Verify whether selected cell is quadranle
199 //=======================================================================
200 // name : SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter
201 // Purpose : Constructor
202 //=======================================================================
203 SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter()
208 SMESHGUI_QuadrangleFilter::~SMESHGUI_QuadrangleFilter()
212 //=======================================================================
213 // name : SMESHGUI_QuadrangleFilter::IsValid
214 // Purpose : Verify whether selected cell is quadranle
215 //=======================================================================
216 bool SMESHGUI_QuadrangleFilter::IsValid( const int theCellId ) const
221 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
222 if ( anActor->GetObject() == 0 )
225 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
226 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
228 return anElem && anElem->GetType() == SMDSAbs_Face &&
229 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 ));
232 //=======================================================================
233 // name : SMESHGUI_QuadrangleFilter::IsValid
234 // Purpose : Verify whether selected cell is quadranle
235 //=======================================================================
236 bool SMESHGUI_QuadrangleFilter::IsObjValid( const int theObjId ) const
241 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
242 if ( anActor->GetObject() == 0 )
245 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
246 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
248 return anElem && anElem->GetType() == SMDSAbs_Face &&
249 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 ));
252 //=======================================================================
253 // name : SMESHGUI_QuadrangleFilter::SetActor
254 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
255 // enumeration. All filters must have different ids
256 //=======================================================================
257 int SMESHGUI_QuadrangleFilter::GetId() const
259 return SMESHGUI_QuadFilter;
262 //=======================================================================
263 // name : SMESHGUI_QuadrangleFilter::IsNodeFilter
264 // Purpose : Returns true if filter is intended for nodes
265 //=======================================================================
266 bool SMESHGUI_QuadrangleFilter::IsNodeFilter() const
273 Class : SMESHGUI_TriangleFilter
274 Description : Verify whether selected cell is triangle
278 //=======================================================================
279 // name : SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter
280 // Purpose : Constructor
281 //=======================================================================
282 SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter()
287 SMESHGUI_TriangleFilter::~SMESHGUI_TriangleFilter()
291 //=======================================================================
292 // name : SMESHGUI_TriangleFilter::IsValid
293 // Purpose : Verify whether selected cell is triangle
294 //=======================================================================
295 bool SMESHGUI_TriangleFilter::IsValid( const int theCellId ) const
300 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
301 if ( anActor->GetObject() == 0 )
304 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
305 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
307 return anElem && anElem->GetType() == SMDSAbs_Face &&
308 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6 : 3 ));
311 //=======================================================================
312 // name : SMESHGUI_TriangleFilter::IsValid
313 // Purpose : Verify whether selected cell is triangle
314 //=======================================================================
315 bool SMESHGUI_TriangleFilter::IsObjValid( const int theObjId ) const
320 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
321 if ( anActor->GetObject() == 0 )
324 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
325 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
327 return anElem && anElem->GetType() == SMDSAbs_Face &&
328 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6 : 3 ));
331 //=======================================================================
332 // name : SMESHGUI_TriangleFilter::SetActor
333 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
334 // enumeration. All filters must have different ids
335 //=======================================================================
336 int SMESHGUI_TriangleFilter::GetId() const
338 return SMESHGUI_TriaFilter;
341 //=======================================================================
342 // name : SMESHGUI_TriangleFilter::IsNodeFilter
343 // Purpose : Returns true if filter is intended for nodes
344 //=======================================================================
345 bool SMESHGUI_TriangleFilter::IsNodeFilter() const
351 Class : SMESHGUI_FacesFilter
352 Description : Verify whether selected cell is any face
356 //=======================================================================
357 // name : SMESHGUI_FacesFilter::SMESHGUI_FacesFilter
358 // Purpose : Constructor
359 //=======================================================================
360 SMESHGUI_FacesFilter::SMESHGUI_FacesFilter()
365 SMESHGUI_FacesFilter::~SMESHGUI_FacesFilter()
369 //=======================================================================
370 // name : SMESHGUI_FacesFilter::IsValid
371 // Purpose : Verify whether selected cell is face
372 //=======================================================================
373 bool SMESHGUI_FacesFilter::IsValid( const int theCellId ) const
378 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
379 if ( anActor->GetObject() == 0 )
382 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
383 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
385 return anElem && anElem->GetType() == SMDSAbs_Face;
388 //=======================================================================
389 // name : SMESHGUI_FacesFilter::IsValid
390 // Purpose : Verify whether selected cell is face
391 //=======================================================================
392 bool SMESHGUI_FacesFilter::IsObjValid( const int theObjId ) const
397 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
398 if ( anActor->GetObject() == 0 )
401 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
402 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
404 return anElem && anElem->GetType() == SMDSAbs_Face;
407 //=======================================================================
408 // name : SMESHGUI_FacesFilter::GetId
409 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
410 // enumeration. All filters must have different ids
411 //=======================================================================
412 int SMESHGUI_FacesFilter::GetId() const
414 return SMESHGUI_FaceFilter;
417 //=======================================================================
418 // name : SMESHGUI_FacesFilter::IsNodeFilter
419 // Purpose : Returns true if filter is intended for nodes
420 //=======================================================================
421 bool SMESHGUI_FacesFilter::IsNodeFilter() const
428 Class : SMESHGUI_VolumesFilter
429 Description : Verify whether selected cell is any volume
433 //=======================================================================
434 // name : SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter
435 // Purpose : Constructor
436 //=======================================================================
437 SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter()
442 SMESHGUI_VolumesFilter::~SMESHGUI_VolumesFilter()
446 //=======================================================================
447 // name : SMESHGUI_VolumesFilter::IsValid
448 // Purpose : Verify whether selected cell is volume
449 //=======================================================================
450 bool SMESHGUI_VolumesFilter::IsValid( const int theCellId ) const
455 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
456 if ( anActor->GetObject() == 0 )
459 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
460 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
462 return anElem && anElem->GetType() == SMDSAbs_Volume;
465 //=======================================================================
466 // name : SMESHGUI_VolumesFilter::IsValid
467 // Purpose : Verify whether selected cell is volume
468 //=======================================================================
469 bool SMESHGUI_VolumesFilter::IsObjValid( const int theObjId ) const
474 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
475 if ( anActor->GetObject() == 0 )
478 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
479 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
481 return anElem && anElem->GetType() == SMDSAbs_Volume;
484 //=======================================================================
485 // name : SMESHGUI_VolumesFilter::GetId
486 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
487 // enumeration. All filters must have different ids
488 //=======================================================================
489 int SMESHGUI_VolumesFilter::GetId() const
491 return SMESHGUI_VolumeFilter;
494 //=======================================================================
495 // name : SMESHGUI_VolumesFilter::IsNodeFilter
496 // Purpose : Returns true if filter is intended for nodes
497 //=======================================================================
498 bool SMESHGUI_VolumesFilter::IsNodeFilter() const