1 // Copyright (C) 2007-2016 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 OCCT_IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_Filter, VTKViewer_Filter)
37 OCCT_IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_PredicateFilter, SMESHGUI_Filter)
38 OCCT_IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_QuadrangleFilter, SMESHGUI_Filter)
39 OCCT_IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_TriangleFilter, SMESHGUI_Filter)
40 OCCT_IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_FacesFilter, SMESHGUI_Filter)
41 OCCT_IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_VolumesFilter, SMESHGUI_Filter)
42 OCCT_IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_VolumeShapeFilter, SMESHGUI_Filter)
45 Class : SMESHGUI_PredicateFilter
46 Description : Selection filter for VTK viewer. This class aggregate object
47 of SMESH_Predicate class and uses it for verification of criterion
50 //=======================================================================
51 // name : SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter
52 // Purpose : Constructor
53 //=======================================================================
54 SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter()
58 SMESHGUI_PredicateFilter::~SMESHGUI_PredicateFilter()
62 //=======================================================================
63 // name : SMESHGUI_PredicateFilter::IsValid
64 // Purpose : Verify whether entry id satisfies to criterion of the filter
65 //=======================================================================
66 bool SMESHGUI_PredicateFilter::IsValid( const int theCellId ) const
68 if ( myActor == 0 || myPred->_is_nil() )
71 SMESH_Actor* anActor = dynamic_cast<SMESH_Actor*>( myActor );
72 if ( !anActor || anActor->GetObject() == 0 )
75 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
76 SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)myPred->GetElementType();
77 int aMeshId = anElemType == SMDSAbs_Node ? anActor->GetNodeObjId( theCellId )
78 : anActor->GetElemObjId( theCellId );
80 // if type of element != type of predicate return true because
81 // this predicate is not intended for filtering sush elements
82 const SMDS_MeshElement* anElem = anElemType == SMDSAbs_Node ? aMesh->FindNode( aMeshId )
83 : aMesh->FindElement( aMeshId );
84 // here we guess that predicate element type can not be All in case of node selection
85 if ( !anElem || (anElemType != SMDSAbs_All && anElem->GetType() != anElemType) )
88 return myPred->IsSatisfy( aMeshId );
91 //=======================================================================
92 // name : SMESHGUI_PredicateFilter::IsValid
93 // Purpose : Verify whether entry id satisfies to criterion of the filter
94 //=======================================================================
95 bool SMESHGUI_PredicateFilter::IsObjValid( const int theObjId ) const
97 if ( myActor == 0 || myPred->_is_nil() )
100 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
101 if ( !anActor || anActor->GetObject() == 0 )
104 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
105 SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)myPred->GetElementType();
107 // if type of element != type of predicate return true because
108 // this predicate is not intended for filtering sush elements
109 const SMDS_MeshElement* anElem = anElemType == SMDSAbs_Node ? aMesh->FindNode( theObjId )
110 : aMesh->FindElement( theObjId );
111 // here we guess that predicate element type can not be All in case of node selection
112 if ( !anElem || (anElemType != SMDSAbs_All && anElem->GetType() != anElemType) )
115 return myPred->IsSatisfy( theObjId );
118 //=======================================================================
119 // name : SMESHGUI_PredicateFilter::IsNodeFilter
120 // Purpose : Returns true if filter is intended for nodes
121 //=======================================================================
122 bool SMESHGUI_PredicateFilter::IsNodeFilter() const
124 return GetId() == SMESH::NodeFilter;
127 //=======================================================================
128 // name : SMESHGUI_PredicateFilter::SetPredicate
129 // Purpose : Set new pridicate to the filter
130 //=======================================================================
131 void SMESHGUI_PredicateFilter::SetPredicate( SMESH::Predicate_ptr thePred )
133 myPred = SMESH::Predicate::_duplicate( thePred );
136 //=======================================================================
137 // name : SMESHGUI_PredicateFilter::SetActor
138 // Purpose : Set new actor
139 //=======================================================================
140 void SMESHGUI_PredicateFilter::SetActor( SALOME_Actor* theActor )
142 if ( myActor == theActor )
144 SMESHGUI_Filter::SetActor( theActor );
146 if ( myActor != 0 && !myPred->_is_nil() )
148 SALOME_Actor* sActor = dynamic_cast<SALOME_Actor*>( myActor );
149 Handle(SALOME_InteractiveObject) anIO;
151 anIO = sActor->getIO();
152 if ( !anIO.IsNull() )
154 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
155 if(!aMesh->_is_nil())
156 myPred->SetMesh(aMesh);
161 //=======================================================================
162 // name : SMESHGUI_PredicateFilter::SetActor
163 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
164 // enumeration. All filters must have different ids
165 //=======================================================================
166 int SMESHGUI_PredicateFilter::GetId() const
168 if ( myPred->GetElementType() == SMESH::NODE ) return SMESH::NodeFilter;
169 else if ( myPred->GetElementType() == SMESH::EDGE ) return SMESH::EdgeFilter;
170 else if ( myPred->GetElementType() == SMESH::FACE ) return SMESH::FaceFilter;
171 else if ( myPred->GetElementType() == SMESH::VOLUME ) return SMESH::VolumeFilter;
172 else if ( myPred->GetElementType() == SMESH::ALL ) return SMESH::AllElementsFilter;
173 else return SMESH::UnknownFilter;
178 Class : SMESHGUI_QuadrangleFilter
179 Description : Verify whether selected cell is quadranle
182 //=======================================================================
183 // name : SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter
184 // Purpose : Constructor
185 //=======================================================================
186 SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter()
191 SMESHGUI_QuadrangleFilter::~SMESHGUI_QuadrangleFilter()
195 //=======================================================================
196 // name : SMESHGUI_QuadrangleFilter::IsValid
197 // Purpose : Verify whether selected cell is quadranle
198 //=======================================================================
199 bool SMESHGUI_QuadrangleFilter::IsValid( const int theCellId ) const
204 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
205 if ( !anActor || anActor->GetObject() == 0 )
208 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
209 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
211 return anElem && anElem->GetType() == SMDSAbs_Face &&
212 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 ));
215 //=======================================================================
216 // name : SMESHGUI_QuadrangleFilter::IsValid
217 // Purpose : Verify whether selected cell is quadranle
218 //=======================================================================
219 bool SMESHGUI_QuadrangleFilter::IsObjValid( const int theObjId ) const
224 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
225 if ( !anActor || anActor->GetObject() == 0 )
228 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
229 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
231 return anElem && anElem->GetType() == SMDSAbs_Face &&
232 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 ));
235 //=======================================================================
236 // name : SMESHGUI_QuadrangleFilter::SetActor
237 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
238 // enumeration. All filters must have different ids
239 //=======================================================================
240 int SMESHGUI_QuadrangleFilter::GetId() const
242 return SMESH::QuadFilter;
245 //=======================================================================
246 // name : SMESHGUI_QuadrangleFilter::IsNodeFilter
247 // Purpose : Returns true if filter is intended for nodes
248 //=======================================================================
249 bool SMESHGUI_QuadrangleFilter::IsNodeFilter() const
256 Class : SMESHGUI_TriangleFilter
257 Description : Verify whether selected cell is triangle
261 //=======================================================================
262 // name : SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter
263 // Purpose : Constructor
264 //=======================================================================
265 SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter()
270 SMESHGUI_TriangleFilter::~SMESHGUI_TriangleFilter()
274 //=======================================================================
275 // name : SMESHGUI_TriangleFilter::IsValid
276 // Purpose : Verify whether selected cell is triangle
277 //=======================================================================
278 bool SMESHGUI_TriangleFilter::IsValid( const int theCellId ) const
283 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
284 if ( !anActor || anActor->GetObject() == 0 )
287 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
288 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
290 return anElem && anElem->GetType() == SMDSAbs_Face &&
291 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6 : 3 ));
294 //=======================================================================
295 // name : SMESHGUI_TriangleFilter::IsValid
296 // Purpose : Verify whether selected cell is triangle
297 //=======================================================================
298 bool SMESHGUI_TriangleFilter::IsObjValid( const int theObjId ) const
303 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
304 if ( !anActor || anActor->GetObject() == 0 )
307 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
308 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
310 return anElem && anElem->GetType() == SMDSAbs_Face &&
311 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6 : 3 ));
314 //=======================================================================
315 // name : SMESHGUI_TriangleFilter::SetActor
316 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
317 // enumeration. All filters must have different ids
318 //=======================================================================
319 int SMESHGUI_TriangleFilter::GetId() const
321 return SMESH::TriaFilter;
324 //=======================================================================
325 // name : SMESHGUI_TriangleFilter::IsNodeFilter
326 // Purpose : Returns true if filter is intended for nodes
327 //=======================================================================
328 bool SMESHGUI_TriangleFilter::IsNodeFilter() const
334 Class : SMESHGUI_FacesFilter
335 Description : Verify whether selected cell is any face
339 //=======================================================================
340 // name : SMESHGUI_FacesFilter::SMESHGUI_FacesFilter
341 // Purpose : Constructor
342 //=======================================================================
343 SMESHGUI_FacesFilter::SMESHGUI_FacesFilter()
348 SMESHGUI_FacesFilter::~SMESHGUI_FacesFilter()
352 //=======================================================================
353 // name : SMESHGUI_FacesFilter::IsValid
354 // Purpose : Verify whether selected cell is face
355 //=======================================================================
356 bool SMESHGUI_FacesFilter::IsValid( const int theCellId ) const
361 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
362 if ( !anActor || anActor->GetObject() == 0 )
365 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
366 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
368 return anElem && anElem->GetType() == SMDSAbs_Face;
371 //=======================================================================
372 // name : SMESHGUI_FacesFilter::IsValid
373 // Purpose : Verify whether selected cell is face
374 //=======================================================================
375 bool SMESHGUI_FacesFilter::IsObjValid( const int theObjId ) const
380 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
381 if ( !anActor || anActor->GetObject() == 0 )
384 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
385 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
387 return anElem && anElem->GetType() == SMDSAbs_Face;
390 //=======================================================================
391 // name : SMESHGUI_FacesFilter::GetId
392 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
393 // enumeration. All filters must have different ids
394 //=======================================================================
395 int SMESHGUI_FacesFilter::GetId() const
397 return SMESH::FaceFilter;
400 //=======================================================================
401 // name : SMESHGUI_FacesFilter::IsNodeFilter
402 // Purpose : Returns true if filter is intended for nodes
403 //=======================================================================
404 bool SMESHGUI_FacesFilter::IsNodeFilter() const
411 Class : SMESHGUI_VolumesFilter
412 Description : Verify whether selected cell is any volume
416 //=======================================================================
417 // name : SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter
418 // Purpose : Constructor
419 //=======================================================================
420 SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter()
425 SMESHGUI_VolumesFilter::~SMESHGUI_VolumesFilter()
429 //=======================================================================
430 // name : SMESHGUI_VolumesFilter::IsValid
431 // Purpose : Verify whether selected cell is volume
432 //=======================================================================
433 bool SMESHGUI_VolumesFilter::IsValid( const int theCellId ) const
435 if ( myActor == 0 || theCellId < 1 )
438 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
439 if ( !anActor || anActor->GetObject() == 0 )
442 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
443 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
445 return anElem && anElem->GetType() == SMDSAbs_Volume;
448 //=======================================================================
449 // name : SMESHGUI_VolumesFilter::IsValid
450 // Purpose : Verify whether selected cell is volume
451 //=======================================================================
452 bool SMESHGUI_VolumesFilter::IsObjValid( const int theObjId ) const
457 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
458 if ( !anActor || anActor->GetObject() == 0 )
461 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
462 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
464 return anElem && anElem->GetType() == SMDSAbs_Volume;
467 //=======================================================================
468 // name : SMESHGUI_VolumesFilter::GetId
469 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
470 // enumeration. All filters must have different ids
471 //=======================================================================
472 int SMESHGUI_VolumesFilter::GetId() const
474 return SMESH::VolumeFilter;
477 //=======================================================================
478 // name : SMESHGUI_VolumesFilter::IsNodeFilter
479 // Purpose : Returns true if filter is intended for nodes
480 //=======================================================================
481 bool SMESHGUI_VolumesFilter::IsNodeFilter() const
488 Class : SMESHGUI_VolumeShapeFilter
489 Description : Verify whether selected cell is a volume of a certain shape
493 //=======================================================================
494 // name : SMESHGUI_VolumeShapeFilter::SMESHGUI_VolumeShapeFilter
495 // Purpose : Constructor
496 //=======================================================================
497 SMESHGUI_VolumeShapeFilter::SMESHGUI_VolumeShapeFilter(const SMDSAbs_GeometryType shape)
498 : SMESHGUI_Filter(), myGeometryType( shape )
502 //=======================================================================
503 // name : SMESHGUI_VolumeShapeFilter::IsValid
504 // Purpose : Verify whether selected cell is a volume of a certain shape
505 //=======================================================================
506 bool SMESHGUI_VolumeShapeFilter::IsValid( const int theCellId ) const
508 if ( myActor == 0 || theCellId < 1 )
511 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
512 if ( !anActor || anActor->GetObject() == 0 )
515 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
516 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
518 return anElem && anElem->GetGeomType() == myGeometryType;
521 //=======================================================================
522 // name : SMESHGUI_VolumeShapeFilter::IsValid
523 // Purpose : Verify whether selected cell is volume
524 //=======================================================================
525 bool SMESHGUI_VolumeShapeFilter::IsObjValid( const int theObjId ) const
530 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
531 if ( !anActor || anActor->GetObject() == 0 )
534 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
535 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
537 return anElem && anElem->GetGeomType() == myGeometryType;
540 //=======================================================================
541 // name : SMESHGUI_VolumeShapeFilter::GetId
542 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
543 // enumeration. All filters must have different ids
544 //=======================================================================
545 int SMESHGUI_VolumeShapeFilter::GetId() const
547 return GetId( myGeometryType );
550 //=======================================================================
552 //purpose : Compose filter ID basing on
553 //=======================================================================
555 int SMESHGUI_VolumeShapeFilter::GetId( SMDSAbs_GeometryType shape )
557 return SMESH::FirstGeometryTypeFilter + shape;
560 //=======================================================================
561 // name : SMESHGUI_VolumeShapeFilter::IsNodeFilter
562 // Purpose : Returns true if filter is intended for nodes
563 //=======================================================================
564 bool SMESHGUI_VolumeShapeFilter::IsNodeFilter() const