1 // Copyright (C) 2007-2014 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 // SMESHGUI_Filter : Filters for VTK viewer
24 // File : SMESHGUI_Filter.cxx
25 // Author : Sergey LITONIN, Open CASCADE S.A.S.
28 #include "SMESHGUI_Filter.h"
30 #include "SMESHGUI_Utils.h"
32 #include <SMESH_Actor.h>
33 #include <SMDS_Mesh.hxx>
34 #include <SMDSAbs_ElementType.hxx>
36 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_Filter, VTKViewer_Filter)
37 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_Filter, VTKViewer_Filter)
39 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_PredicateFilter, SMESHGUI_Filter)
40 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_PredicateFilter, SMESHGUI_Filter)
42 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_QuadrangleFilter, SMESHGUI_Filter)
43 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_QuadrangleFilter, SMESHGUI_Filter)
45 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_TriangleFilter, SMESHGUI_Filter)
46 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_TriangleFilter, SMESHGUI_Filter)
48 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_FacesFilter, SMESHGUI_Filter)
49 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_FacesFilter, SMESHGUI_Filter)
51 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_VolumesFilter, SMESHGUI_Filter)
52 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_VolumesFilter, SMESHGUI_Filter)
54 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_VolumeShapeFilter, SMESHGUI_Filter)
55 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_VolumeShapeFilter, SMESHGUI_Filter)
58 Class : SMESHGUI_PredicateFilter
59 Description : Selection filter for VTK viewer. This class aggregate object
60 of SMESH_Predicate class and uses it for verification of criterion
63 //=======================================================================
64 // name : SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter
65 // Purpose : Constructor
66 //=======================================================================
67 SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter()
71 SMESHGUI_PredicateFilter::~SMESHGUI_PredicateFilter()
75 //=======================================================================
76 // name : SMESHGUI_PredicateFilter::IsValid
77 // Purpose : Verify whether entry id satisfies to criterion of the filter
78 //=======================================================================
79 bool SMESHGUI_PredicateFilter::IsValid( const int theCellId ) const
81 if ( myActor == 0 || myPred->_is_nil() )
84 SMESH_Actor* anActor = dynamic_cast<SMESH_Actor*>( myActor );
85 if ( !anActor || anActor->GetObject() == 0 )
88 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
89 SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)myPred->GetElementType();
90 int aMeshId = anElemType == SMDSAbs_Node ? anActor->GetNodeObjId( theCellId )
91 : anActor->GetElemObjId( theCellId );
93 // if type of element != type of predicate return true because
94 // this predicate is not intended for filtering sush elements
95 const SMDS_MeshElement* anElem = anElemType == SMDSAbs_Node ? aMesh->FindNode( aMeshId )
96 : aMesh->FindElement( aMeshId );
97 // here we guess that predicate element type can not be All in case of node selection
98 if ( !anElem || (anElemType != SMDSAbs_All && anElem->GetType() != anElemType) )
101 return myPred->IsSatisfy( aMeshId );
104 //=======================================================================
105 // name : SMESHGUI_PredicateFilter::IsValid
106 // Purpose : Verify whether entry id satisfies to criterion of the filter
107 //=======================================================================
108 bool SMESHGUI_PredicateFilter::IsObjValid( const int theObjId ) const
110 if ( myActor == 0 || myPred->_is_nil() )
113 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
114 if ( !anActor || anActor->GetObject() == 0 )
117 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
118 SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)myPred->GetElementType();
120 // if type of element != type of predicate return true because
121 // this predicate is not intended for filtering sush elements
122 const SMDS_MeshElement* anElem = anElemType == SMDSAbs_Node ? aMesh->FindNode( theObjId )
123 : aMesh->FindElement( theObjId );
124 // here we guess that predicate element type can not be All in case of node selection
125 if ( !anElem || (anElemType != SMDSAbs_All && anElem->GetType() != anElemType) )
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() == SMESH::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 SALOME_Actor* sActor = dynamic_cast<SALOME_Actor*>( myActor );
162 Handle(SALOME_InteractiveObject) anIO;
164 anIO = sActor->getIO();
165 if ( !anIO.IsNull() )
167 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
168 if(!aMesh->_is_nil())
169 myPred->SetMesh(aMesh);
174 //=======================================================================
175 // name : SMESHGUI_PredicateFilter::SetActor
176 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
177 // enumeration. All filters must have different ids
178 //=======================================================================
179 int SMESHGUI_PredicateFilter::GetId() const
181 if ( myPred->GetElementType() == SMESH::NODE ) return SMESH::NodeFilter;
182 else if ( myPred->GetElementType() == SMESH::EDGE ) return SMESH::EdgeFilter;
183 else if ( myPred->GetElementType() == SMESH::FACE ) return SMESH::FaceFilter;
184 else if ( myPred->GetElementType() == SMESH::VOLUME ) return SMESH::VolumeFilter;
185 else if ( myPred->GetElementType() == SMESH::ALL ) return SMESH::AllElementsFilter;
186 else return SMESH::UnknownFilter;
191 Class : SMESHGUI_QuadrangleFilter
192 Description : Verify whether selected cell is quadranle
195 //=======================================================================
196 // name : SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter
197 // Purpose : Constructor
198 //=======================================================================
199 SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter()
204 SMESHGUI_QuadrangleFilter::~SMESHGUI_QuadrangleFilter()
208 //=======================================================================
209 // name : SMESHGUI_QuadrangleFilter::IsValid
210 // Purpose : Verify whether selected cell is quadranle
211 //=======================================================================
212 bool SMESHGUI_QuadrangleFilter::IsValid( const int theCellId ) const
217 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
218 if ( !anActor || anActor->GetObject() == 0 )
221 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
222 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
224 return anElem && anElem->GetType() == SMDSAbs_Face &&
225 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 ));
228 //=======================================================================
229 // name : SMESHGUI_QuadrangleFilter::IsValid
230 // Purpose : Verify whether selected cell is quadranle
231 //=======================================================================
232 bool SMESHGUI_QuadrangleFilter::IsObjValid( const int theObjId ) const
237 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
238 if ( !anActor || anActor->GetObject() == 0 )
241 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
242 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
244 return anElem && anElem->GetType() == SMDSAbs_Face &&
245 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 ));
248 //=======================================================================
249 // name : SMESHGUI_QuadrangleFilter::SetActor
250 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
251 // enumeration. All filters must have different ids
252 //=======================================================================
253 int SMESHGUI_QuadrangleFilter::GetId() const
255 return SMESH::QuadFilter;
258 //=======================================================================
259 // name : SMESHGUI_QuadrangleFilter::IsNodeFilter
260 // Purpose : Returns true if filter is intended for nodes
261 //=======================================================================
262 bool SMESHGUI_QuadrangleFilter::IsNodeFilter() const
269 Class : SMESHGUI_TriangleFilter
270 Description : Verify whether selected cell is triangle
274 //=======================================================================
275 // name : SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter
276 // Purpose : Constructor
277 //=======================================================================
278 SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter()
283 SMESHGUI_TriangleFilter::~SMESHGUI_TriangleFilter()
287 //=======================================================================
288 // name : SMESHGUI_TriangleFilter::IsValid
289 // Purpose : Verify whether selected cell is triangle
290 //=======================================================================
291 bool SMESHGUI_TriangleFilter::IsValid( const int theCellId ) const
296 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
297 if ( !anActor || anActor->GetObject() == 0 )
300 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
301 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
303 return anElem && anElem->GetType() == SMDSAbs_Face &&
304 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6 : 3 ));
307 //=======================================================================
308 // name : SMESHGUI_TriangleFilter::IsValid
309 // Purpose : Verify whether selected cell is triangle
310 //=======================================================================
311 bool SMESHGUI_TriangleFilter::IsObjValid( const int theObjId ) const
316 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
317 if ( !anActor || anActor->GetObject() == 0 )
320 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
321 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
323 return anElem && anElem->GetType() == SMDSAbs_Face &&
324 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6 : 3 ));
327 //=======================================================================
328 // name : SMESHGUI_TriangleFilter::SetActor
329 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
330 // enumeration. All filters must have different ids
331 //=======================================================================
332 int SMESHGUI_TriangleFilter::GetId() const
334 return SMESH::TriaFilter;
337 //=======================================================================
338 // name : SMESHGUI_TriangleFilter::IsNodeFilter
339 // Purpose : Returns true if filter is intended for nodes
340 //=======================================================================
341 bool SMESHGUI_TriangleFilter::IsNodeFilter() const
347 Class : SMESHGUI_FacesFilter
348 Description : Verify whether selected cell is any face
352 //=======================================================================
353 // name : SMESHGUI_FacesFilter::SMESHGUI_FacesFilter
354 // Purpose : Constructor
355 //=======================================================================
356 SMESHGUI_FacesFilter::SMESHGUI_FacesFilter()
361 SMESHGUI_FacesFilter::~SMESHGUI_FacesFilter()
365 //=======================================================================
366 // name : SMESHGUI_FacesFilter::IsValid
367 // Purpose : Verify whether selected cell is face
368 //=======================================================================
369 bool SMESHGUI_FacesFilter::IsValid( const int theCellId ) const
374 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
375 if ( !anActor || anActor->GetObject() == 0 )
378 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
379 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
381 return anElem && anElem->GetType() == SMDSAbs_Face;
384 //=======================================================================
385 // name : SMESHGUI_FacesFilter::IsValid
386 // Purpose : Verify whether selected cell is face
387 //=======================================================================
388 bool SMESHGUI_FacesFilter::IsObjValid( const int theObjId ) const
393 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
394 if ( !anActor || anActor->GetObject() == 0 )
397 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
398 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
400 return anElem && anElem->GetType() == SMDSAbs_Face;
403 //=======================================================================
404 // name : SMESHGUI_FacesFilter::GetId
405 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
406 // enumeration. All filters must have different ids
407 //=======================================================================
408 int SMESHGUI_FacesFilter::GetId() const
410 return SMESH::FaceFilter;
413 //=======================================================================
414 // name : SMESHGUI_FacesFilter::IsNodeFilter
415 // Purpose : Returns true if filter is intended for nodes
416 //=======================================================================
417 bool SMESHGUI_FacesFilter::IsNodeFilter() const
424 Class : SMESHGUI_VolumesFilter
425 Description : Verify whether selected cell is any volume
429 //=======================================================================
430 // name : SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter
431 // Purpose : Constructor
432 //=======================================================================
433 SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter()
438 SMESHGUI_VolumesFilter::~SMESHGUI_VolumesFilter()
442 //=======================================================================
443 // name : SMESHGUI_VolumesFilter::IsValid
444 // Purpose : Verify whether selected cell is volume
445 //=======================================================================
446 bool SMESHGUI_VolumesFilter::IsValid( const int theCellId ) const
448 if ( myActor == 0 || theCellId < 1 )
451 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
452 if ( !anActor || anActor->GetObject() == 0 )
455 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
456 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
458 return anElem && anElem->GetType() == SMDSAbs_Volume;
461 //=======================================================================
462 // name : SMESHGUI_VolumesFilter::IsValid
463 // Purpose : Verify whether selected cell is volume
464 //=======================================================================
465 bool SMESHGUI_VolumesFilter::IsObjValid( const int theObjId ) const
470 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
471 if ( !anActor || anActor->GetObject() == 0 )
474 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
475 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
477 return anElem && anElem->GetType() == SMDSAbs_Volume;
480 //=======================================================================
481 // name : SMESHGUI_VolumesFilter::GetId
482 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
483 // enumeration. All filters must have different ids
484 //=======================================================================
485 int SMESHGUI_VolumesFilter::GetId() const
487 return SMESH::VolumeFilter;
490 //=======================================================================
491 // name : SMESHGUI_VolumesFilter::IsNodeFilter
492 // Purpose : Returns true if filter is intended for nodes
493 //=======================================================================
494 bool SMESHGUI_VolumesFilter::IsNodeFilter() const
501 Class : SMESHGUI_VolumeShapeFilter
502 Description : Verify whether selected cell is a volume of a certain shape
506 //=======================================================================
507 // name : SMESHGUI_VolumeShapeFilter::SMESHGUI_VolumeShapeFilter
508 // Purpose : Constructor
509 //=======================================================================
510 SMESHGUI_VolumeShapeFilter::SMESHGUI_VolumeShapeFilter(const SMDSAbs_GeometryType shape)
511 : SMESHGUI_Filter(), myGeometryType( shape )
515 //=======================================================================
516 // name : SMESHGUI_VolumeShapeFilter::IsValid
517 // Purpose : Verify whether selected cell is a volume of a certain shape
518 //=======================================================================
519 bool SMESHGUI_VolumeShapeFilter::IsValid( const int theCellId ) const
521 if ( myActor == 0 || theCellId < 1 )
524 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
525 if ( !anActor || anActor->GetObject() == 0 )
528 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
529 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
531 return anElem && anElem->GetGeomType() == myGeometryType;
534 //=======================================================================
535 // name : SMESHGUI_VolumeShapeFilter::IsValid
536 // Purpose : Verify whether selected cell is volume
537 //=======================================================================
538 bool SMESHGUI_VolumeShapeFilter::IsObjValid( const int theObjId ) const
543 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
544 if ( !anActor || anActor->GetObject() == 0 )
547 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
548 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
550 return anElem && anElem->GetGeomType() == myGeometryType;
553 //=======================================================================
554 // name : SMESHGUI_VolumeShapeFilter::GetId
555 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
556 // enumeration. All filters must have different ids
557 //=======================================================================
558 int SMESHGUI_VolumeShapeFilter::GetId() const
560 return GetId( myGeometryType );
563 //=======================================================================
565 //purpose : Compose filter ID basing on
566 //=======================================================================
568 int SMESHGUI_VolumeShapeFilter::GetId( SMDSAbs_GeometryType shape )
570 return SMESH::FirstGeometryTypeFilter + shape;
573 //=======================================================================
574 // name : SMESHGUI_VolumeShapeFilter::IsNodeFilter
575 // Purpose : Returns true if filter is intended for nodes
576 //=======================================================================
577 bool SMESHGUI_VolumeShapeFilter::IsNodeFilter() const