1 // Copyright (C) 2007-2013 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.
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)
55 Class : SMESHGUI_PredicateFilter
56 Description : Selection filter for VTK viewer. This class aggregate object
57 of SMESH_Predicate class and uses it for verification of criterion
60 //=======================================================================
61 // name : SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter
62 // Purpose : Constructor
63 //=======================================================================
64 SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter()
68 SMESHGUI_PredicateFilter::~SMESHGUI_PredicateFilter()
72 //=======================================================================
73 // name : SMESHGUI_PredicateFilter::IsValid
74 // Purpose : Verify whether entry id satisfies to criterion of the filter
75 //=======================================================================
76 bool SMESHGUI_PredicateFilter::IsValid( const int theCellId ) const
78 if ( myActor == 0 || myPred->_is_nil() )
81 SMESH_Actor* anActor = dynamic_cast<SMESH_Actor*>( myActor );
82 if ( !anActor || anActor->GetObject() == 0 )
85 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
86 SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)myPred->GetElementType();
87 int aMeshId = anElemType == SMDSAbs_Node ? anActor->GetNodeObjId( theCellId )
88 : anActor->GetElemObjId( theCellId );
90 // if type of element != type of predicate return true because
91 // this predicate is not intended for filtering sush elements
92 const SMDS_MeshElement* anElem = anElemType == SMDSAbs_Node ? aMesh->FindNode( aMeshId )
93 : aMesh->FindElement( aMeshId );
94 // here we guess that predicate element type can not be All in case of node selection
95 if ( !anElem || (anElemType != SMDSAbs_All && anElem->GetType() != anElemType) )
98 return myPred->IsSatisfy( aMeshId );
101 //=======================================================================
102 // name : SMESHGUI_PredicateFilter::IsValid
103 // Purpose : Verify whether entry id satisfies to criterion of the filter
104 //=======================================================================
105 bool SMESHGUI_PredicateFilter::IsObjValid( const int theObjId ) const
107 if ( myActor == 0 || myPred->_is_nil() )
110 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
111 if ( !anActor || anActor->GetObject() == 0 )
114 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
115 SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)myPred->GetElementType();
117 // if type of element != type of predicate return true because
118 // this predicate is not intended for filtering sush elements
119 const SMDS_MeshElement* anElem = anElemType == SMDSAbs_Node ? aMesh->FindNode( theObjId )
120 : aMesh->FindElement( theObjId );
121 // here we guess that predicate element type can not be All in case of node selection
122 if ( !anElem || (anElemType != SMDSAbs_All && anElem->GetType() != anElemType) )
125 return myPred->IsSatisfy( theObjId );
128 //=======================================================================
129 // name : SMESHGUI_PredicateFilter::IsNodeFilter
130 // Purpose : Returns true if filter is intended for nodes
131 //=======================================================================
132 bool SMESHGUI_PredicateFilter::IsNodeFilter() const
134 return GetId() == SMESH::NodeFilter;
137 //=======================================================================
138 // name : SMESHGUI_PredicateFilter::SetPredicate
139 // Purpose : Set new pridicate to the filter
140 //=======================================================================
141 void SMESHGUI_PredicateFilter::SetPredicate( SMESH::Predicate_ptr thePred )
143 myPred = SMESH::Predicate::_duplicate( thePred );
146 //=======================================================================
147 // name : SMESHGUI_PredicateFilter::SetActor
148 // Purpose : Set new actor
149 //=======================================================================
150 void SMESHGUI_PredicateFilter::SetActor( SALOME_Actor* theActor )
152 if ( myActor == theActor )
154 SMESHGUI_Filter::SetActor( theActor );
156 if ( myActor != 0 && !myPred->_is_nil() )
158 SALOME_Actor* sActor = dynamic_cast<SALOME_Actor*>( myActor );
159 Handle(SALOME_InteractiveObject) anIO;
161 anIO = sActor->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 SMESH::NodeFilter;
179 else if ( myPred->GetElementType() == SMESH::EDGE ) return SMESH::EdgeFilter;
180 else if ( myPred->GetElementType() == SMESH::FACE ) return SMESH::FaceFilter;
181 else if ( myPred->GetElementType() == SMESH::VOLUME ) return SMESH::VolumeFilter;
182 else if ( myPred->GetElementType() == SMESH::ALL ) return SMESH::AllElementsFilter;
183 else return SMESH::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 = dynamic_cast< SMESH_Actor* >( myActor );
215 if ( !anActor || 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 &&
222 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 ));
225 //=======================================================================
226 // name : SMESHGUI_QuadrangleFilter::IsValid
227 // Purpose : Verify whether selected cell is quadranle
228 //=======================================================================
229 bool SMESHGUI_QuadrangleFilter::IsObjValid( const int theObjId ) const
234 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
235 if ( !anActor || anActor->GetObject() == 0 )
238 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
239 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
241 return anElem && anElem->GetType() == SMDSAbs_Face &&
242 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 ));
245 //=======================================================================
246 // name : SMESHGUI_QuadrangleFilter::SetActor
247 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
248 // enumeration. All filters must have different ids
249 //=======================================================================
250 int SMESHGUI_QuadrangleFilter::GetId() const
252 return SMESH::QuadFilter;
255 //=======================================================================
256 // name : SMESHGUI_QuadrangleFilter::IsNodeFilter
257 // Purpose : Returns true if filter is intended for nodes
258 //=======================================================================
259 bool SMESHGUI_QuadrangleFilter::IsNodeFilter() const
266 Class : SMESHGUI_TriangleFilter
267 Description : Verify whether selected cell is triangle
271 //=======================================================================
272 // name : SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter
273 // Purpose : Constructor
274 //=======================================================================
275 SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter()
280 SMESHGUI_TriangleFilter::~SMESHGUI_TriangleFilter()
284 //=======================================================================
285 // name : SMESHGUI_TriangleFilter::IsValid
286 // Purpose : Verify whether selected cell is triangle
287 //=======================================================================
288 bool SMESHGUI_TriangleFilter::IsValid( const int theCellId ) const
293 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
294 if ( !anActor || anActor->GetObject() == 0 )
297 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
298 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
300 return anElem && anElem->GetType() == SMDSAbs_Face &&
301 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6 : 3 ));
304 //=======================================================================
305 // name : SMESHGUI_TriangleFilter::IsValid
306 // Purpose : Verify whether selected cell is triangle
307 //=======================================================================
308 bool SMESHGUI_TriangleFilter::IsObjValid( const int theObjId ) const
313 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
314 if ( !anActor || anActor->GetObject() == 0 )
317 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
318 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
320 return anElem && anElem->GetType() == SMDSAbs_Face &&
321 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6 : 3 ));
324 //=======================================================================
325 // name : SMESHGUI_TriangleFilter::SetActor
326 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
327 // enumeration. All filters must have different ids
328 //=======================================================================
329 int SMESHGUI_TriangleFilter::GetId() const
331 return SMESH::TriaFilter;
334 //=======================================================================
335 // name : SMESHGUI_TriangleFilter::IsNodeFilter
336 // Purpose : Returns true if filter is intended for nodes
337 //=======================================================================
338 bool SMESHGUI_TriangleFilter::IsNodeFilter() const
344 Class : SMESHGUI_FacesFilter
345 Description : Verify whether selected cell is any face
349 //=======================================================================
350 // name : SMESHGUI_FacesFilter::SMESHGUI_FacesFilter
351 // Purpose : Constructor
352 //=======================================================================
353 SMESHGUI_FacesFilter::SMESHGUI_FacesFilter()
358 SMESHGUI_FacesFilter::~SMESHGUI_FacesFilter()
362 //=======================================================================
363 // name : SMESHGUI_FacesFilter::IsValid
364 // Purpose : Verify whether selected cell is face
365 //=======================================================================
366 bool SMESHGUI_FacesFilter::IsValid( const int theCellId ) const
371 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
372 if ( !anActor || anActor->GetObject() == 0 )
375 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
376 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
378 return anElem && anElem->GetType() == SMDSAbs_Face;
381 //=======================================================================
382 // name : SMESHGUI_FacesFilter::IsValid
383 // Purpose : Verify whether selected cell is face
384 //=======================================================================
385 bool SMESHGUI_FacesFilter::IsObjValid( const int theObjId ) const
390 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
391 if ( !anActor || anActor->GetObject() == 0 )
394 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
395 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
397 return anElem && anElem->GetType() == SMDSAbs_Face;
400 //=======================================================================
401 // name : SMESHGUI_FacesFilter::GetId
402 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
403 // enumeration. All filters must have different ids
404 //=======================================================================
405 int SMESHGUI_FacesFilter::GetId() const
407 return SMESH::FaceFilter;
410 //=======================================================================
411 // name : SMESHGUI_FacesFilter::IsNodeFilter
412 // Purpose : Returns true if filter is intended for nodes
413 //=======================================================================
414 bool SMESHGUI_FacesFilter::IsNodeFilter() const
421 Class : SMESHGUI_VolumesFilter
422 Description : Verify whether selected cell is any volume
426 //=======================================================================
427 // name : SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter
428 // Purpose : Constructor
429 //=======================================================================
430 SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter()
435 SMESHGUI_VolumesFilter::~SMESHGUI_VolumesFilter()
439 //=======================================================================
440 // name : SMESHGUI_VolumesFilter::IsValid
441 // Purpose : Verify whether selected cell is volume
442 //=======================================================================
443 bool SMESHGUI_VolumesFilter::IsValid( const int theCellId ) const
445 if ( myActor == 0 || theCellId < 1 )
448 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
449 if ( !anActor || anActor->GetObject() == 0 )
452 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
453 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
455 return anElem && anElem->GetType() == SMDSAbs_Volume;
458 //=======================================================================
459 // name : SMESHGUI_VolumesFilter::IsValid
460 // Purpose : Verify whether selected cell is volume
461 //=======================================================================
462 bool SMESHGUI_VolumesFilter::IsObjValid( const int theObjId ) const
467 SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
468 if ( !anActor || anActor->GetObject() == 0 )
471 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
472 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
474 return anElem && anElem->GetType() == SMDSAbs_Volume;
477 //=======================================================================
478 // name : SMESHGUI_VolumesFilter::GetId
479 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
480 // enumeration. All filters must have different ids
481 //=======================================================================
482 int SMESHGUI_VolumesFilter::GetId() const
484 return SMESH::VolumeFilter;
487 //=======================================================================
488 // name : SMESHGUI_VolumesFilter::IsNodeFilter
489 // Purpose : Returns true if filter is intended for nodes
490 //=======================================================================
491 bool SMESHGUI_VolumesFilter::IsNodeFilter() const