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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_Filter.cxx
25 // Author : Sergey LITONIN
28 #include "SMESHGUI_Filter.h"
29 #include "SMESHGUI_Utils.h"
30 #include "SMDS_Mesh.hxx"
31 #include "SMDS_MeshElement.hxx"
32 #include "SMDSAbs_ElementType.hxx"
37 #include <Precision.hxx>
38 #include "SMESH_Actor.h"
41 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_Filter, VTKViewer_Filter)
42 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_Filter, VTKViewer_Filter)
44 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_PredicateFilter, SMESHGUI_Filter)
45 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_PredicateFilter, SMESHGUI_Filter)
47 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_QuadrangleFilter, SMESHGUI_Filter)
48 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_QuadrangleFilter, SMESHGUI_Filter)
50 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_TriangleFilter, SMESHGUI_Filter)
51 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_TriangleFilter, SMESHGUI_Filter)
53 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_FacesFilter, SMESHGUI_Filter)
54 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_FacesFilter, SMESHGUI_Filter)
56 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_VolumesFilter, SMESHGUI_Filter)
57 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_VolumesFilter, SMESHGUI_Filter)
60 Class : SMESHGUI_PredicateFilter
61 Description : Selection filter for VTK viewer. This class aggregate object
62 of SMESH_Predicate class and uses it for verification of criterion
65 //=======================================================================
66 // name : SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter
67 // Purpose : Constructor
68 //=======================================================================
69 SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter()
73 SMESHGUI_PredicateFilter::~SMESHGUI_PredicateFilter()
77 //=======================================================================
78 // name : SMESHGUI_PredicateFilter::IsValid
79 // Purpose : Verify whether entry id satisfies to criterion of the filter
80 //=======================================================================
81 bool SMESHGUI_PredicateFilter::IsValid( const int theCellId ) const
83 if ( myActor == 0 || myPred->_is_nil() )
86 SMESH_Actor* anActor = dynamic_cast<SMESH_Actor*>( myActor );
87 if ( !anActor || anActor->GetObject() == 0 )
90 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
91 SMESH::ElementType anElemType = myPred->GetElementType();
92 int aMeshId = anElemType == SMESH::NODE ? anActor->GetNodeObjId( theCellId )
93 : anActor->GetElemObjId( theCellId );
95 // if type of element != type of predicate return true because
96 // this predicate is not intended for filtering sush elements
97 const SMDS_MeshElement* anElem = anElemType == SMESH::NODE ? aMesh->FindNode( aMeshId )
98 : aMesh->FindElement( aMeshId );
99 if ( anElem != 0 && anElem->GetType() != (SMDSAbs_ElementType)myPred->GetElementType() )
102 return myPred->IsSatisfy( aMeshId );
105 //=======================================================================
106 // name : SMESHGUI_PredicateFilter::IsValid
107 // Purpose : Verify whether entry id satisfies to criterion of the filter
108 //=======================================================================
109 bool SMESHGUI_PredicateFilter::IsObjValid( const int theObjId ) const
111 if ( myActor == 0 || myPred->_is_nil() )
114 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
115 if ( anActor->GetObject() == 0 )
118 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
119 SMESH::ElementType anElemType = myPred->GetElementType();
121 // if type of element != type of predicate return true because
122 // this predicate is not intended for filtering sush elements
123 const SMDS_MeshElement* anElem = anElemType == SMESH::NODE ? aMesh->FindNode( theObjId )
124 : aMesh->FindElement( theObjId );
125 if ( anElem != 0 && anElem->GetType() != (SMDSAbs_ElementType)myPred->GetElementType() )
128 return myPred->IsSatisfy( theObjId );
131 //=======================================================================
132 // name : SMESHGUI_PredicateFilter::IsNodeFilter
133 // Purpose : Returns true if filter is intended for nodes
134 //=======================================================================
135 bool SMESHGUI_PredicateFilter::IsNodeFilter() const
137 return GetId() == SMESHGUI_NodeFilter;
140 //=======================================================================
141 // name : SMESHGUI_PredicateFilter::SetPredicate
142 // Purpose : Set new pridicate to the filter
143 //=======================================================================
144 void SMESHGUI_PredicateFilter::SetPredicate( SMESH::Predicate_ptr thePred )
146 myPred = SMESH::Predicate::_duplicate( thePred );
149 //=======================================================================
150 // name : SMESHGUI_PredicateFilter::SetActor
151 // Purpose : Set new actor
152 //=======================================================================
153 void SMESHGUI_PredicateFilter::SetActor( SALOME_Actor* theActor )
155 if ( myActor == theActor )
157 SMESHGUI_Filter::SetActor( theActor );
159 if ( myActor != 0 && !myPred->_is_nil() )
161 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
162 if ( !anIO.IsNull() )
164 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
165 if(!aMesh->_is_nil())
166 myPred->SetMesh(aMesh);
171 //=======================================================================
172 // name : SMESHGUI_PredicateFilter::SetActor
173 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
174 // enumeration. All filters must have different ids
175 //=======================================================================
176 int SMESHGUI_PredicateFilter::GetId() const
178 if ( myPred->GetElementType() == SMESH::NODE ) return SMESHGUI_NodeFilter;
179 else if ( myPred->GetElementType() == SMESH::EDGE ) return SMESHGUI_EdgeFilter;
180 else if ( myPred->GetElementType() == SMESH::FACE ) return SMESHGUI_FaceFilter;
181 else if ( myPred->GetElementType() == SMESH::VOLUME ) return SMESHGUI_VolumeFilter;
182 else if ( myPred->GetElementType() == SMESH::ALL ) return SMESHGUI_AllElementsFilter;
183 else return SMESHGUI_UnknownFilter;
188 Class : SMESHGUI_QuadrangleFilter
189 Description : Verify whether selected cell is quadranle
192 //=======================================================================
193 // name : SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter
194 // Purpose : Constructor
195 //=======================================================================
196 SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter()
201 SMESHGUI_QuadrangleFilter::~SMESHGUI_QuadrangleFilter()
205 //=======================================================================
206 // name : SMESHGUI_QuadrangleFilter::IsValid
207 // Purpose : Verify whether selected cell is quadranle
208 //=======================================================================
209 bool SMESHGUI_QuadrangleFilter::IsValid( const int theCellId ) const
214 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
215 if ( anActor->GetObject() == 0 )
218 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
219 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
221 return anElem && anElem->GetType() == SMDSAbs_Face && anElem->NbNodes() == 4;
224 //=======================================================================
225 // name : SMESHGUI_QuadrangleFilter::IsValid
226 // Purpose : Verify whether selected cell is quadranle
227 //=======================================================================
228 bool SMESHGUI_QuadrangleFilter::IsObjValid( const int theObjId ) const
233 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
234 if ( anActor->GetObject() == 0 )
237 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
238 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
240 return anElem && anElem->GetType() == SMDSAbs_Face && anElem->NbNodes() == 4;
243 //=======================================================================
244 // name : SMESHGUI_QuadrangleFilter::SetActor
245 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
246 // enumeration. All filters must have different ids
247 //=======================================================================
248 int SMESHGUI_QuadrangleFilter::GetId() const
250 return SMESHGUI_QuadFilter;
253 //=======================================================================
254 // name : SMESHGUI_QuadrangleFilter::IsNodeFilter
255 // Purpose : Returns true if filter is intended for nodes
256 //=======================================================================
257 bool SMESHGUI_QuadrangleFilter::IsNodeFilter() const
264 Class : SMESHGUI_TriangleFilter
265 Description : Verify whether selected cell is triangle
269 //=======================================================================
270 // name : SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter
271 // Purpose : Constructor
272 //=======================================================================
273 SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter()
278 SMESHGUI_TriangleFilter::~SMESHGUI_TriangleFilter()
282 //=======================================================================
283 // name : SMESHGUI_TriangleFilter::IsValid
284 // Purpose : Verify whether selected cell is triangle
285 //=======================================================================
286 bool SMESHGUI_TriangleFilter::IsValid( const int theCellId ) const
291 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
292 if ( anActor->GetObject() == 0 )
295 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
296 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
298 return anElem && anElem->GetType() == SMDSAbs_Face && anElem->NbNodes() == 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 && anElem->NbNodes() == 3;
320 //=======================================================================
321 // name : SMESHGUI_TriangleFilter::SetActor
322 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
323 // enumeration. All filters must have different ids
324 //=======================================================================
325 int SMESHGUI_TriangleFilter::GetId() const
327 return SMESHGUI_TriaFilter;
330 //=======================================================================
331 // name : SMESHGUI_TriangleFilter::IsNodeFilter
332 // Purpose : Returns true if filter is intended for nodes
333 //=======================================================================
334 bool SMESHGUI_TriangleFilter::IsNodeFilter() const
340 Class : SMESHGUI_FacesFilter
341 Description : Verify whether selected cell is any face
345 //=======================================================================
346 // name : SMESHGUI_FacesFilter::SMESHGUI_FacesFilter
347 // Purpose : Constructor
348 //=======================================================================
349 SMESHGUI_FacesFilter::SMESHGUI_FacesFilter()
354 SMESHGUI_FacesFilter::~SMESHGUI_FacesFilter()
358 //=======================================================================
359 // name : SMESHGUI_FacesFilter::IsValid
360 // Purpose : Verify whether selected cell is face
361 //=======================================================================
362 bool SMESHGUI_FacesFilter::IsValid( const int theCellId ) const
367 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
368 if ( anActor->GetObject() == 0 )
371 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
372 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
374 return anElem && anElem->GetType() == SMDSAbs_Face;
377 //=======================================================================
378 // name : SMESHGUI_FacesFilter::IsValid
379 // Purpose : Verify whether selected cell is face
380 //=======================================================================
381 bool SMESHGUI_FacesFilter::IsObjValid( const int theObjId ) const
386 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
387 if ( anActor->GetObject() == 0 )
390 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
391 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
393 return anElem && anElem->GetType() == SMDSAbs_Face;
396 //=======================================================================
397 // name : SMESHGUI_FacesFilter::GetId
398 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
399 // enumeration. All filters must have different ids
400 //=======================================================================
401 int SMESHGUI_FacesFilter::GetId() const
403 return SMESHGUI_FaceFilter;
406 //=======================================================================
407 // name : SMESHGUI_FacesFilter::IsNodeFilter
408 // Purpose : Returns true if filter is intended for nodes
409 //=======================================================================
410 bool SMESHGUI_FacesFilter::IsNodeFilter() const
417 Class : SMESHGUI_VolumesFilter
418 Description : Verify whether selected cell is any volume
422 //=======================================================================
423 // name : SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter
424 // Purpose : Constructor
425 //=======================================================================
426 SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter()
431 SMESHGUI_VolumesFilter::~SMESHGUI_VolumesFilter()
435 //=======================================================================
436 // name : SMESHGUI_VolumesFilter::IsValid
437 // Purpose : Verify whether selected cell is volume
438 //=======================================================================
439 bool SMESHGUI_VolumesFilter::IsValid( const int theCellId ) const
444 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
445 if ( anActor->GetObject() == 0 )
448 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
449 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
451 return anElem && anElem->GetType() == SMDSAbs_Volume;
454 //=======================================================================
455 // name : SMESHGUI_VolumesFilter::IsValid
456 // Purpose : Verify whether selected cell is volume
457 //=======================================================================
458 bool SMESHGUI_VolumesFilter::IsObjValid( const int theObjId ) const
463 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
464 if ( anActor->GetObject() == 0 )
467 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
468 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
470 return anElem && anElem->GetType() == SMDSAbs_Volume;
473 //=======================================================================
474 // name : SMESHGUI_VolumesFilter::GetId
475 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
476 // enumeration. All filters must have different ids
477 //=======================================================================
478 int SMESHGUI_VolumesFilter::GetId() const
480 return SMESHGUI_VolumeFilter;
483 //=======================================================================
484 // name : SMESHGUI_VolumesFilter::IsNodeFilter
485 // Purpose : Returns true if filter is intended for nodes
486 //=======================================================================
487 bool SMESHGUI_VolumesFilter::IsNodeFilter() const