1 // Copyright (C) 2007-2008 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
22 // SMESHGUI_PredicateFilter : Filters for VTK viewer
23 // File : SMESHGUI_Filter.cxx
24 // Author : Sergey LITONIN
27 #include "SMESHGUI_Filter.h"
30 #include "SMESHGUI_Utils.h"
32 #include "SMESH_Actor.h"
33 #include "SMDS_Mesh.hxx"
34 #include "SMDS_MeshElement.hxx"
35 #include "SMDSAbs_ElementType.hxx"
39 #include <Precision.hxx>
44 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_Filter, VTKViewer_Filter)
45 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_Filter, VTKViewer_Filter)
47 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_PredicateFilter, SMESHGUI_Filter)
48 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_PredicateFilter, SMESHGUI_Filter)
50 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_QuadrangleFilter, SMESHGUI_Filter)
51 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_QuadrangleFilter, SMESHGUI_Filter)
53 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_TriangleFilter, SMESHGUI_Filter)
54 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_TriangleFilter, SMESHGUI_Filter)
56 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_FacesFilter, SMESHGUI_Filter)
57 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_FacesFilter, SMESHGUI_Filter)
59 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_VolumesFilter, SMESHGUI_Filter)
60 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_VolumesFilter, SMESHGUI_Filter)
63 Class : SMESHGUI_PredicateFilter
64 Description : Selection filter for VTK viewer. This class aggregate object
65 of SMESH_Predicate class and uses it for verification of criterion
68 //=======================================================================
69 // name : SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter
70 // Purpose : Constructor
71 //=======================================================================
72 SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter()
76 SMESHGUI_PredicateFilter::~SMESHGUI_PredicateFilter()
80 //=======================================================================
81 // name : SMESHGUI_PredicateFilter::IsValid
82 // Purpose : Verify whether entry id satisfies to criterion of the filter
83 //=======================================================================
84 bool SMESHGUI_PredicateFilter::IsValid( const int theCellId ) const
86 if ( myActor == 0 || myPred->_is_nil() )
89 SMESH_Actor* anActor = dynamic_cast<SMESH_Actor*>( myActor );
90 if ( !anActor || anActor->GetObject() == 0 )
93 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
94 SMESH::ElementType anElemType = myPred->GetElementType();
95 int aMeshId = anElemType == SMESH::NODE ? anActor->GetNodeObjId( theCellId )
96 : anActor->GetElemObjId( theCellId );
98 // if type of element != type of predicate return true because
99 // this predicate is not intended for filtering sush elements
100 const SMDS_MeshElement* anElem = anElemType == SMESH::NODE ? aMesh->FindNode( aMeshId )
101 : aMesh->FindElement( aMeshId );
102 if ( anElem != 0 && anElem->GetType() != (SMDSAbs_ElementType)myPred->GetElementType() )
105 return myPred->IsSatisfy( aMeshId );
108 //=======================================================================
109 // name : SMESHGUI_PredicateFilter::IsValid
110 // Purpose : Verify whether entry id satisfies to criterion of the filter
111 //=======================================================================
112 bool SMESHGUI_PredicateFilter::IsObjValid( const int theObjId ) const
114 if ( myActor == 0 || myPred->_is_nil() )
117 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
118 if ( anActor->GetObject() == 0 )
121 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
122 SMESH::ElementType anElemType = myPred->GetElementType();
124 // if type of element != type of predicate return true because
125 // this predicate is not intended for filtering sush elements
126 const SMDS_MeshElement* anElem = anElemType == SMESH::NODE ? aMesh->FindNode( theObjId )
127 : aMesh->FindElement( theObjId );
128 if ( anElem != 0 && anElem->GetType() != (SMDSAbs_ElementType)myPred->GetElementType() )
131 return myPred->IsSatisfy( theObjId );
134 //=======================================================================
135 // name : SMESHGUI_PredicateFilter::IsNodeFilter
136 // Purpose : Returns true if filter is intended for nodes
137 //=======================================================================
138 bool SMESHGUI_PredicateFilter::IsNodeFilter() const
140 return GetId() == SMESHGUI_NodeFilter;
143 //=======================================================================
144 // name : SMESHGUI_PredicateFilter::SetPredicate
145 // Purpose : Set new pridicate to the filter
146 //=======================================================================
147 void SMESHGUI_PredicateFilter::SetPredicate( SMESH::Predicate_ptr thePred )
149 myPred = SMESH::Predicate::_duplicate( thePred );
152 //=======================================================================
153 // name : SMESHGUI_PredicateFilter::SetActor
154 // Purpose : Set new actor
155 //=======================================================================
156 void SMESHGUI_PredicateFilter::SetActor( SALOME_Actor* theActor )
158 if ( myActor == theActor )
160 SMESHGUI_Filter::SetActor( theActor );
162 if ( myActor != 0 && !myPred->_is_nil() )
164 SALOME_Actor* sActor = dynamic_cast<SALOME_Actor*>( myActor );
165 Handle(SALOME_InteractiveObject) anIO;
167 anIO = sActor->getIO();
168 if ( !anIO.IsNull() )
170 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
171 if(!aMesh->_is_nil())
172 myPred->SetMesh(aMesh);
177 //=======================================================================
178 // name : SMESHGUI_PredicateFilter::SetActor
179 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
180 // enumeration. All filters must have different ids
181 //=======================================================================
182 int SMESHGUI_PredicateFilter::GetId() const
184 if ( myPred->GetElementType() == SMESH::NODE ) return SMESHGUI_NodeFilter;
185 else if ( myPred->GetElementType() == SMESH::EDGE ) return SMESHGUI_EdgeFilter;
186 else if ( myPred->GetElementType() == SMESH::FACE ) return SMESHGUI_FaceFilter;
187 else if ( myPred->GetElementType() == SMESH::VOLUME ) return SMESHGUI_VolumeFilter;
188 else if ( myPred->GetElementType() == SMESH::ALL ) return SMESHGUI_AllElementsFilter;
189 else return SMESHGUI_UnknownFilter;
194 Class : SMESHGUI_QuadrangleFilter
195 Description : Verify whether selected cell is quadranle
198 //=======================================================================
199 // name : SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter
200 // Purpose : Constructor
201 //=======================================================================
202 SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter()
207 SMESHGUI_QuadrangleFilter::~SMESHGUI_QuadrangleFilter()
211 //=======================================================================
212 // name : SMESHGUI_QuadrangleFilter::IsValid
213 // Purpose : Verify whether selected cell is quadranle
214 //=======================================================================
215 bool SMESHGUI_QuadrangleFilter::IsValid( const int theCellId ) const
220 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
221 if ( anActor->GetObject() == 0 )
224 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
225 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
227 return anElem && anElem->GetType() == SMDSAbs_Face &&
228 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 ));
231 //=======================================================================
232 // name : SMESHGUI_QuadrangleFilter::IsValid
233 // Purpose : Verify whether selected cell is quadranle
234 //=======================================================================
235 bool SMESHGUI_QuadrangleFilter::IsObjValid( const int theObjId ) const
240 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
241 if ( anActor->GetObject() == 0 )
244 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
245 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
247 return anElem && anElem->GetType() == SMDSAbs_Face &&
248 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 ));
251 //=======================================================================
252 // name : SMESHGUI_QuadrangleFilter::SetActor
253 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
254 // enumeration. All filters must have different ids
255 //=======================================================================
256 int SMESHGUI_QuadrangleFilter::GetId() const
258 return SMESHGUI_QuadFilter;
261 //=======================================================================
262 // name : SMESHGUI_QuadrangleFilter::IsNodeFilter
263 // Purpose : Returns true if filter is intended for nodes
264 //=======================================================================
265 bool SMESHGUI_QuadrangleFilter::IsNodeFilter() const
272 Class : SMESHGUI_TriangleFilter
273 Description : Verify whether selected cell is triangle
277 //=======================================================================
278 // name : SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter
279 // Purpose : Constructor
280 //=======================================================================
281 SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter()
286 SMESHGUI_TriangleFilter::~SMESHGUI_TriangleFilter()
290 //=======================================================================
291 // name : SMESHGUI_TriangleFilter::IsValid
292 // Purpose : Verify whether selected cell is triangle
293 //=======================================================================
294 bool SMESHGUI_TriangleFilter::IsValid( const int theCellId ) const
299 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
300 if ( anActor->GetObject() == 0 )
303 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
304 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
306 return anElem && anElem->GetType() == SMDSAbs_Face &&
307 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6 : 3 ));
310 //=======================================================================
311 // name : SMESHGUI_TriangleFilter::IsValid
312 // Purpose : Verify whether selected cell is triangle
313 //=======================================================================
314 bool SMESHGUI_TriangleFilter::IsObjValid( const int theObjId ) const
319 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
320 if ( anActor->GetObject() == 0 )
323 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
324 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
326 return anElem && anElem->GetType() == SMDSAbs_Face &&
327 ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6 : 3 ));
330 //=======================================================================
331 // name : SMESHGUI_TriangleFilter::SetActor
332 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
333 // enumeration. All filters must have different ids
334 //=======================================================================
335 int SMESHGUI_TriangleFilter::GetId() const
337 return SMESHGUI_TriaFilter;
340 //=======================================================================
341 // name : SMESHGUI_TriangleFilter::IsNodeFilter
342 // Purpose : Returns true if filter is intended for nodes
343 //=======================================================================
344 bool SMESHGUI_TriangleFilter::IsNodeFilter() const
350 Class : SMESHGUI_FacesFilter
351 Description : Verify whether selected cell is any face
355 //=======================================================================
356 // name : SMESHGUI_FacesFilter::SMESHGUI_FacesFilter
357 // Purpose : Constructor
358 //=======================================================================
359 SMESHGUI_FacesFilter::SMESHGUI_FacesFilter()
364 SMESHGUI_FacesFilter::~SMESHGUI_FacesFilter()
368 //=======================================================================
369 // name : SMESHGUI_FacesFilter::IsValid
370 // Purpose : Verify whether selected cell is face
371 //=======================================================================
372 bool SMESHGUI_FacesFilter::IsValid( const int theCellId ) const
377 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
378 if ( anActor->GetObject() == 0 )
381 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
382 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
384 return anElem && anElem->GetType() == SMDSAbs_Face;
387 //=======================================================================
388 // name : SMESHGUI_FacesFilter::IsValid
389 // Purpose : Verify whether selected cell is face
390 //=======================================================================
391 bool SMESHGUI_FacesFilter::IsObjValid( const int theObjId ) const
396 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
397 if ( anActor->GetObject() == 0 )
400 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
401 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
403 return anElem && anElem->GetType() == SMDSAbs_Face;
406 //=======================================================================
407 // name : SMESHGUI_FacesFilter::GetId
408 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
409 // enumeration. All filters must have different ids
410 //=======================================================================
411 int SMESHGUI_FacesFilter::GetId() const
413 return SMESHGUI_FaceFilter;
416 //=======================================================================
417 // name : SMESHGUI_FacesFilter::IsNodeFilter
418 // Purpose : Returns true if filter is intended for nodes
419 //=======================================================================
420 bool SMESHGUI_FacesFilter::IsNodeFilter() const
427 Class : SMESHGUI_VolumesFilter
428 Description : Verify whether selected cell is any volume
432 //=======================================================================
433 // name : SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter
434 // Purpose : Constructor
435 //=======================================================================
436 SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter()
441 SMESHGUI_VolumesFilter::~SMESHGUI_VolumesFilter()
445 //=======================================================================
446 // name : SMESHGUI_VolumesFilter::IsValid
447 // Purpose : Verify whether selected cell is volume
448 //=======================================================================
449 bool SMESHGUI_VolumesFilter::IsValid( const int theCellId ) const
454 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
455 if ( anActor->GetObject() == 0 )
458 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
459 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
461 return anElem && anElem->GetType() == SMDSAbs_Volume;
464 //=======================================================================
465 // name : SMESHGUI_VolumesFilter::IsValid
466 // Purpose : Verify whether selected cell is volume
467 //=======================================================================
468 bool SMESHGUI_VolumesFilter::IsObjValid( const int theObjId ) const
473 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
474 if ( anActor->GetObject() == 0 )
477 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
478 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
480 return anElem && anElem->GetType() == SMDSAbs_Volume;
483 //=======================================================================
484 // name : SMESHGUI_VolumesFilter::GetId
485 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
486 // enumeration. All filters must have different ids
487 //=======================================================================
488 int SMESHGUI_VolumesFilter::GetId() const
490 return SMESHGUI_VolumeFilter;
493 //=======================================================================
494 // name : SMESHGUI_VolumesFilter::IsNodeFilter
495 // Purpose : Returns true if filter is intended for nodes
496 //=======================================================================
497 bool SMESHGUI_VolumesFilter::IsNodeFilter() const