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)
54 Class : SMESHGUI_PredicateFilter
55 Description : Selection filter for VTK viewer. This class aggregate object
56 of SMESH_Predicate class and uses it for verification of criterion
59 //=======================================================================
60 // name : SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter
61 // Purpose : Constructor
62 //=======================================================================
63 SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter()
67 SMESHGUI_PredicateFilter::~SMESHGUI_PredicateFilter()
71 //=======================================================================
72 // name : SMESHGUI_PredicateFilter::IsValid
73 // Purpose : Verify whether entry id satisfies to criterion of the filter
74 //=======================================================================
75 bool SMESHGUI_PredicateFilter::IsValid( const int theCellId ) const
77 if ( myActor == 0 || myPred->_is_nil() )
80 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
81 if ( anActor->GetObject() == 0 )
84 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
85 SMESH::ElementType anElemType = myPred->GetElementType();
86 int aMeshId = anElemType == SMESH::NODE ? anActor->GetNodeObjId( theCellId )
87 : anActor->GetElemObjId( theCellId );
89 // if type of element != type of predicate return true because
90 // this predicate is not intended for filtering sush elements
91 const SMDS_MeshElement* anElem = anElemType == SMESH::NODE ? aMesh->FindNode( aMeshId )
92 : aMesh->FindElement( aMeshId );
93 if ( anElem != 0 && anElem->GetType() != (SMDSAbs_ElementType)myPred->GetElementType() )
96 return myPred->IsSatisfy( aMeshId );
99 //=======================================================================
100 // name : SMESHGUI_PredicateFilter::IsValid
101 // Purpose : Verify whether entry id satisfies to criterion of the filter
102 //=======================================================================
103 bool SMESHGUI_PredicateFilter::IsObjValid( const int theObjId ) const
105 if ( myActor == 0 || myPred->_is_nil() )
108 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
109 if ( anActor->GetObject() == 0 )
112 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
113 SMESH::ElementType anElemType = myPred->GetElementType();
115 // if type of element != type of predicate return true because
116 // this predicate is not intended for filtering sush elements
117 const SMDS_MeshElement* anElem = anElemType == SMESH::NODE ? aMesh->FindNode( theObjId )
118 : aMesh->FindElement( theObjId );
119 if ( anElem != 0 && anElem->GetType() != (SMDSAbs_ElementType)myPred->GetElementType() )
122 return myPred->IsSatisfy( theObjId );
125 //=======================================================================
126 // name : SMESHGUI_PredicateFilter::IsNodeFilter
127 // Purpose : Returns true if filter is intended for nodes
128 //=======================================================================
129 bool SMESHGUI_PredicateFilter::IsNodeFilter() const
131 return GetId() == SMESHGUI_NodeFilter;
134 //=======================================================================
135 // name : SMESHGUI_PredicateFilter::SetPredicate
136 // Purpose : Set new pridicate to the filter
137 //=======================================================================
138 void SMESHGUI_PredicateFilter::SetPredicate( SMESH::Predicate_ptr thePred )
140 myPred = SMESH::Predicate::_duplicate( thePred );
143 //=======================================================================
144 // name : SMESHGUI_PredicateFilter::SetActor
145 // Purpose : Set new actor
146 //=======================================================================
147 void SMESHGUI_PredicateFilter::SetActor( SALOME_Actor* theActor )
149 if ( myActor == theActor )
151 SMESHGUI_Filter::SetActor( theActor );
153 if ( myActor != 0 && !myPred->_is_nil() )
155 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
156 if ( !anIO.IsNull() )
158 SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
159 if(!aMesh->_is_nil())
160 myPred->SetMesh(aMesh);
165 //=======================================================================
166 // name : SMESHGUI_PredicateFilter::SetActor
167 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
168 // enumeration. All filters must have different ids
169 //=======================================================================
170 int SMESHGUI_PredicateFilter::GetId() const
172 if ( myPred->GetElementType() == SMESH::NODE ) return SMESHGUI_NodeFilter;
173 else if ( myPred->GetElementType() == SMESH::EDGE ) return SMESHGUI_EdgeFilter;
174 else if ( myPred->GetElementType() == SMESH::FACE ) return SMESHGUI_FaceFilter;
175 else if ( myPred->GetElementType() == SMESH::VOLUME ) return SMESHGUI_VolumeFilter;
176 else if ( myPred->GetElementType() == SMESH::ALL ) return SMESHGUI_AllElementsFilter;
177 else return SMESHGUI_UnknownFilter;
182 Class : SMESHGUI_QuadrangleFilter
183 Description : Verify whether selected cell is quadranle
186 //=======================================================================
187 // name : SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter
188 // Purpose : Constructor
189 //=======================================================================
190 SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter()
195 SMESHGUI_QuadrangleFilter::~SMESHGUI_QuadrangleFilter()
199 //=======================================================================
200 // name : SMESHGUI_QuadrangleFilter::IsValid
201 // Purpose : Verify whether selected cell is quadranle
202 //=======================================================================
203 bool SMESHGUI_QuadrangleFilter::IsValid( const int theCellId ) const
208 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
209 if ( anActor->GetObject() == 0 )
212 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
213 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
215 return anElem != 0 ? anElem->GetType() != SMDSAbs_Face || anElem->NbNodes() == 4 : false;
218 //=======================================================================
219 // name : SMESHGUI_QuadrangleFilter::IsValid
220 // Purpose : Verify whether selected cell is quadranle
221 //=======================================================================
222 bool SMESHGUI_QuadrangleFilter::IsObjValid( const int theObjId ) const
227 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
228 if ( anActor->GetObject() == 0 )
231 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
232 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
234 return anElem != 0 ? anElem->GetType() != SMDSAbs_Face || anElem->NbNodes() == 4 : false;
237 //=======================================================================
238 // name : SMESHGUI_QuadrangleFilter::SetActor
239 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
240 // enumeration. All filters must have different ids
241 //=======================================================================
242 int SMESHGUI_QuadrangleFilter::GetId() const
244 return SMESHGUI_QuadFilter;
247 //=======================================================================
248 // name : SMESHGUI_QuadrangleFilter::IsNodeFilter
249 // Purpose : Returns true if filter is intended for nodes
250 //=======================================================================
251 bool SMESHGUI_QuadrangleFilter::IsNodeFilter() const
258 Class : SMESHGUI_TriangleFilter
259 Description : Verify whether selected cell is triangle
263 //=======================================================================
264 // name : SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter
265 // Purpose : Constructor
266 //=======================================================================
267 SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter()
272 SMESHGUI_TriangleFilter::~SMESHGUI_TriangleFilter()
276 //=======================================================================
277 // name : SMESHGUI_TriangleFilter::IsValid
278 // Purpose : Verify whether selected cell is triangle
279 //=======================================================================
280 bool SMESHGUI_TriangleFilter::IsValid( const int theCellId ) const
285 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
286 if ( anActor->GetObject() == 0 )
289 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
290 const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
292 return anElem != 0 ? anElem->GetType() != SMDSAbs_Face || anElem->NbNodes() == 3 : false;
295 //=======================================================================
296 // name : SMESHGUI_TriangleFilter::IsValid
297 // Purpose : Verify whether selected cell is triangle
298 //=======================================================================
299 bool SMESHGUI_TriangleFilter::IsObjValid( const int theObjId ) const
304 SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
305 if ( anActor->GetObject() == 0 )
308 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
309 const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
311 return anElem != 0 ? anElem->GetType() != SMDSAbs_Face || anElem->NbNodes() == 3 : false;
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 SMESHGUI_TriaFilter;
324 //=======================================================================
325 // name : SMESHGUI_TriangleFilter::IsNodeFilter
326 // Purpose : Returns true if filter is intended for nodes
327 //=======================================================================
328 bool SMESHGUI_TriangleFilter::IsNodeFilter() const