Back to index

salome-smesh  6.5.0
SMESHGUI_Filter.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // SMESHGUI_Filter : Filters for VTK viewer
00024 // File   : SMESHGUI_Filter.cxx
00025 // Author : Sergey LITONIN, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_Filter.h"
00029 
00030 #include "SMESHGUI_Utils.h"
00031 
00032 #include <SMESH_Actor.h>
00033 #include <SMDS_Mesh.hxx>
00034 #include <SMDSAbs_ElementType.hxx>
00035 
00036 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_Filter, VTKViewer_Filter)
00037 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_Filter, VTKViewer_Filter)
00038 
00039 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_PredicateFilter, SMESHGUI_Filter)
00040 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_PredicateFilter, SMESHGUI_Filter)
00041 
00042 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_QuadrangleFilter, SMESHGUI_Filter)
00043 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_QuadrangleFilter, SMESHGUI_Filter)
00044 
00045 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_TriangleFilter, SMESHGUI_Filter)
00046 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_TriangleFilter, SMESHGUI_Filter)
00047 
00048 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_FacesFilter, SMESHGUI_Filter)
00049 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_FacesFilter, SMESHGUI_Filter)
00050 
00051 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_VolumesFilter, SMESHGUI_Filter)
00052 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_VolumesFilter, SMESHGUI_Filter)
00053 
00054 /*
00055   Class       : SMESHGUI_PredicateFilter
00056   Description : Selection filter for VTK viewer. This class aggregate object
00057                 of SMESH_Predicate class and uses it for verification of criterion
00058 */
00059 
00060 //=======================================================================
00061 // name    : SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter
00062 // Purpose : Constructor
00063 //=======================================================================
00064 SMESHGUI_PredicateFilter::SMESHGUI_PredicateFilter()
00065 {
00066 }
00067 
00068 SMESHGUI_PredicateFilter::~SMESHGUI_PredicateFilter()
00069 {
00070 }
00071 
00072 //=======================================================================
00073 // name    : SMESHGUI_PredicateFilter::IsValid
00074 // Purpose : Verify whether entry id satisfies to criterion of the filter
00075 //=======================================================================
00076 bool SMESHGUI_PredicateFilter::IsValid( const int theCellId ) const
00077 {
00078   if ( myActor == 0 || myPred->_is_nil() )
00079     return false;
00080 
00081   SMESH_Actor* anActor = dynamic_cast<SMESH_Actor*>( myActor );
00082   if ( !anActor || anActor->GetObject() == 0 )
00083     return false;
00084 
00085   SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
00086   SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)myPred->GetElementType();
00087   int aMeshId = anElemType == SMDSAbs_Node ? anActor->GetNodeObjId( theCellId )
00088                                            : anActor->GetElemObjId( theCellId );
00089 
00090   // if type of element != type of predicate return true because
00091   // this predicate is not intended for filtering sush elements
00092   const SMDS_MeshElement* anElem = anElemType == SMDSAbs_Node ? aMesh->FindNode( aMeshId )
00093                                                               : aMesh->FindElement( aMeshId );
00094   // here we guess that predicate element type can not be All in case of node selection
00095   if ( !anElem || (anElemType != SMDSAbs_All && anElem->GetType() != anElemType) )
00096     return false;
00097   
00098   return myPred->IsSatisfy( aMeshId );
00099 }
00100 
00101 //=======================================================================
00102 // name    : SMESHGUI_PredicateFilter::IsValid
00103 // Purpose : Verify whether entry id satisfies to criterion of the filter
00104 //=======================================================================
00105 bool SMESHGUI_PredicateFilter::IsObjValid( const int theObjId ) const
00106 {
00107   if ( myActor == 0 || myPred->_is_nil() )
00108     return false;
00109 
00110   SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
00111   if ( !anActor || anActor->GetObject() == 0 )
00112     return false;
00113 
00114   SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
00115   SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)myPred->GetElementType();
00116 
00117   // if type of element != type of predicate return true because
00118   // this predicate is not intended for filtering sush elements
00119   const SMDS_MeshElement* anElem = anElemType == SMDSAbs_Node ? aMesh->FindNode( theObjId )
00120                                                               : aMesh->FindElement( theObjId );
00121   // here we guess that predicate element type can not be All in case of node selection
00122   if ( !anElem || (anElemType != SMDSAbs_All && anElem->GetType() != anElemType) )
00123     return false;
00124 
00125   return myPred->IsSatisfy( theObjId );
00126 }
00127 
00128 //=======================================================================
00129 // name    : SMESHGUI_PredicateFilter::IsNodeFilter
00130 // Purpose : Returns true if filter is intended for nodes
00131 //=======================================================================
00132 bool SMESHGUI_PredicateFilter::IsNodeFilter() const
00133 {
00134   return GetId() == SMESH::NodeFilter;
00135 }
00136 
00137 //=======================================================================
00138 // name    : SMESHGUI_PredicateFilter::SetPredicate
00139 // Purpose : Set new pridicate to the filter
00140 //=======================================================================
00141 void SMESHGUI_PredicateFilter::SetPredicate( SMESH::Predicate_ptr thePred )
00142 {
00143   myPred = SMESH::Predicate::_duplicate( thePred );
00144 }
00145 
00146 //=======================================================================
00147 // name    : SMESHGUI_PredicateFilter::SetActor
00148 // Purpose : Set new actor
00149 //=======================================================================
00150 void SMESHGUI_PredicateFilter::SetActor( SALOME_Actor* theActor )
00151 {
00152   if ( myActor == theActor )
00153     return;
00154   SMESHGUI_Filter::SetActor( theActor );
00155 
00156   if ( myActor != 0 && !myPred->_is_nil() )
00157   {
00158     SALOME_Actor* sActor = dynamic_cast<SALOME_Actor*>( myActor );
00159     Handle(SALOME_InteractiveObject) anIO;
00160     if( sActor )
00161       anIO = sActor->getIO();
00162     if ( !anIO.IsNull() )
00163     {
00164       SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIO);
00165       if(!aMesh->_is_nil())
00166         myPred->SetMesh(aMesh);
00167     }
00168   }
00169 }
00170 
00171 //=======================================================================
00172 // name    : SMESHGUI_PredicateFilter::SetActor
00173 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
00174 //           enumeration. All filters must have different ids
00175 //=======================================================================
00176 int SMESHGUI_PredicateFilter::GetId() const
00177 {
00178   if      ( myPred->GetElementType() == SMESH::NODE   ) return SMESH::NodeFilter;
00179   else if ( myPred->GetElementType() == SMESH::EDGE   ) return SMESH::EdgeFilter;
00180   else if ( myPred->GetElementType() == SMESH::FACE   ) return SMESH::FaceFilter;
00181   else if ( myPred->GetElementType() == SMESH::VOLUME ) return SMESH::VolumeFilter;
00182   else if ( myPred->GetElementType() == SMESH::ALL    ) return SMESH::AllElementsFilter;
00183   else                                                  return SMESH::UnknownFilter;
00184 }
00185 
00186 
00187 /*
00188   Class       : SMESHGUI_QuadrangleFilter
00189   Description : Verify whether selected cell is quadranle
00190 */
00191 
00192 //=======================================================================
00193 // name    : SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter
00194 // Purpose : Constructor
00195 //=======================================================================
00196 SMESHGUI_QuadrangleFilter::SMESHGUI_QuadrangleFilter()
00197 : SMESHGUI_Filter()
00198 {
00199 }
00200 
00201 SMESHGUI_QuadrangleFilter::~SMESHGUI_QuadrangleFilter()
00202 {
00203 }
00204 
00205 //=======================================================================
00206 // name    : SMESHGUI_QuadrangleFilter::IsValid
00207 // Purpose : Verify whether selected cell is quadranle
00208 //=======================================================================
00209 bool SMESHGUI_QuadrangleFilter::IsValid( const int theCellId ) const
00210 {
00211   if ( myActor == 0 )
00212     return false;
00213 
00214   SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
00215   if ( !anActor || anActor->GetObject() == 0 )
00216     return false;
00217 
00218   SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
00219   const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
00220 
00221   return anElem && anElem->GetType() == SMDSAbs_Face &&
00222     ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8 : 4 ));
00223 }
00224 
00225 //=======================================================================
00226 // name    : SMESHGUI_QuadrangleFilter::IsValid
00227 // Purpose : Verify whether selected cell is quadranle
00228 //=======================================================================
00229 bool SMESHGUI_QuadrangleFilter::IsObjValid( const int theObjId ) const
00230 {
00231   if ( myActor == 0 )
00232     return false;
00233 
00234   SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
00235   if ( !anActor || anActor->GetObject() == 0 )
00236     return false;
00237 
00238   SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
00239   const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
00240 
00241   return anElem && anElem->GetType() == SMDSAbs_Face &&
00242     ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 8  : 4 ));
00243 }
00244 
00245 //=======================================================================
00246 // name    : SMESHGUI_QuadrangleFilter::SetActor
00247 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
00248 //           enumeration. All filters must have different ids
00249 //=======================================================================
00250 int SMESHGUI_QuadrangleFilter::GetId() const
00251 {
00252   return SMESH::QuadFilter;
00253 }
00254 
00255 //=======================================================================
00256 // name    : SMESHGUI_QuadrangleFilter::IsNodeFilter
00257 // Purpose : Returns true if filter is intended for nodes
00258 //=======================================================================
00259 bool SMESHGUI_QuadrangleFilter::IsNodeFilter() const
00260 {
00261   return false;
00262 }
00263 
00264 
00265 /*
00266   Class       : SMESHGUI_TriangleFilter
00267   Description : Verify whether selected cell is triangle
00268 */
00269 
00270 
00271 //=======================================================================
00272 // name    : SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter
00273 // Purpose : Constructor
00274 //=======================================================================
00275 SMESHGUI_TriangleFilter::SMESHGUI_TriangleFilter()
00276 : SMESHGUI_Filter()
00277 {
00278 }
00279 
00280 SMESHGUI_TriangleFilter::~SMESHGUI_TriangleFilter()
00281 {
00282 }
00283 
00284 //=======================================================================
00285 // name    : SMESHGUI_TriangleFilter::IsValid
00286 // Purpose : Verify whether selected cell is triangle
00287 //=======================================================================
00288 bool SMESHGUI_TriangleFilter::IsValid( const int theCellId ) const
00289 {
00290   if ( myActor == 0 )
00291     return false;
00292 
00293   SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
00294   if ( !anActor || anActor->GetObject() == 0 )
00295     return false;
00296 
00297   SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
00298   const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
00299 
00300   return anElem && anElem->GetType() == SMDSAbs_Face &&
00301     ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6  : 3 ));
00302 }
00303 
00304 //=======================================================================
00305 // name    : SMESHGUI_TriangleFilter::IsValid
00306 // Purpose : Verify whether selected cell is triangle
00307 //=======================================================================
00308 bool SMESHGUI_TriangleFilter::IsObjValid( const int theObjId ) const
00309 {
00310   if ( myActor == 0 )
00311     return false;
00312 
00313   SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
00314   if ( !anActor || anActor->GetObject() == 0 )
00315     return false;
00316 
00317   SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
00318   const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
00319 
00320   return anElem && anElem->GetType() == SMDSAbs_Face &&
00321     ( anElem->NbNodes() == ( anElem->IsQuadratic() ? 6  : 3 ));
00322 }
00323 
00324 //=======================================================================
00325 // name    : SMESHGUI_TriangleFilter::SetActor
00326 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
00327 //           enumeration. All filters must have different ids
00328 //=======================================================================
00329 int SMESHGUI_TriangleFilter::GetId() const
00330 {
00331   return SMESH::TriaFilter;
00332 }
00333 
00334 //=======================================================================
00335 // name    : SMESHGUI_TriangleFilter::IsNodeFilter
00336 // Purpose : Returns true if filter is intended for nodes
00337 //=======================================================================
00338 bool SMESHGUI_TriangleFilter::IsNodeFilter() const
00339 {
00340   return false;
00341 }
00342 
00343 /*
00344   Class       : SMESHGUI_FacesFilter
00345   Description : Verify whether selected cell is any face
00346 */
00347 
00348 
00349 //=======================================================================
00350 // name    : SMESHGUI_FacesFilter::SMESHGUI_FacesFilter
00351 // Purpose : Constructor
00352 //=======================================================================
00353 SMESHGUI_FacesFilter::SMESHGUI_FacesFilter()
00354 : SMESHGUI_Filter()
00355 {
00356 }
00357 
00358 SMESHGUI_FacesFilter::~SMESHGUI_FacesFilter()
00359 {
00360 }
00361 
00362 //=======================================================================
00363 // name    : SMESHGUI_FacesFilter::IsValid
00364 // Purpose : Verify whether selected cell is face
00365 //=======================================================================
00366 bool SMESHGUI_FacesFilter::IsValid( const int theCellId ) const
00367 {
00368   if ( myActor == 0 )
00369     return false;
00370 
00371   SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
00372   if ( !anActor || anActor->GetObject() == 0 )
00373     return false;
00374 
00375   SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
00376   const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
00377 
00378   return anElem && anElem->GetType() == SMDSAbs_Face;
00379 }
00380 
00381 //=======================================================================
00382 // name    : SMESHGUI_FacesFilter::IsValid
00383 // Purpose : Verify whether selected cell is face
00384 //=======================================================================
00385 bool SMESHGUI_FacesFilter::IsObjValid( const int theObjId ) const
00386 {
00387   if ( myActor == 0 )
00388     return false;
00389 
00390   SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
00391   if ( !anActor || anActor->GetObject() == 0 )
00392     return false;
00393 
00394   SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
00395   const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
00396 
00397   return anElem && anElem->GetType() == SMDSAbs_Face;
00398 }
00399 
00400 //=======================================================================
00401 // name    : SMESHGUI_FacesFilter::GetId
00402 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
00403 //           enumeration. All filters must have different ids
00404 //=======================================================================
00405 int SMESHGUI_FacesFilter::GetId() const
00406 {
00407   return SMESH::FaceFilter;
00408 }
00409 
00410 //=======================================================================
00411 // name    : SMESHGUI_FacesFilter::IsNodeFilter
00412 // Purpose : Returns true if filter is intended for nodes
00413 //=======================================================================
00414 bool SMESHGUI_FacesFilter::IsNodeFilter() const
00415 {
00416   return false;
00417 }
00418 
00419 
00420 /*
00421   Class       : SMESHGUI_VolumesFilter
00422   Description : Verify whether selected cell is any volume
00423 */
00424 
00425 
00426 //=======================================================================
00427 // name    : SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter
00428 // Purpose : Constructor
00429 //=======================================================================
00430 SMESHGUI_VolumesFilter::SMESHGUI_VolumesFilter()
00431 : SMESHGUI_Filter()
00432 {
00433 }
00434 
00435 SMESHGUI_VolumesFilter::~SMESHGUI_VolumesFilter()
00436 {
00437 }
00438 
00439 //=======================================================================
00440 // name    : SMESHGUI_VolumesFilter::IsValid
00441 // Purpose : Verify whether selected cell is volume
00442 //=======================================================================
00443 bool SMESHGUI_VolumesFilter::IsValid( const int theCellId ) const
00444 {
00445   if ( myActor == 0 || theCellId < 1 )
00446     return false;
00447 
00448   SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
00449   if ( !anActor || anActor->GetObject() == 0 )
00450     return false;
00451 
00452   SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
00453   const SMDS_MeshElement* anElem = aMesh->FindElement( anActor->GetElemObjId( theCellId ) );
00454 
00455   return anElem && anElem->GetType() == SMDSAbs_Volume;
00456 }
00457 
00458 //=======================================================================
00459 // name    : SMESHGUI_VolumesFilter::IsValid
00460 // Purpose : Verify whether selected cell is volume
00461 //=======================================================================
00462 bool SMESHGUI_VolumesFilter::IsObjValid( const int theObjId ) const
00463 {
00464   if ( myActor == 0 )
00465     return false;
00466 
00467   SMESH_Actor* anActor = dynamic_cast< SMESH_Actor* >( myActor );
00468   if ( !anActor || anActor->GetObject() == 0 )
00469     return false;
00470 
00471   SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
00472   const SMDS_MeshElement* anElem = aMesh->FindElement( theObjId );
00473 
00474   return anElem && anElem->GetType() == SMDSAbs_Volume;
00475 }
00476 
00477 //=======================================================================
00478 // name    : SMESHGUI_VolumesFilter::GetId
00479 // Purpose : Get ID of the filter. Must return value from SMESHGUI_FilterType
00480 //           enumeration. All filters must have different ids
00481 //=======================================================================
00482 int SMESHGUI_VolumesFilter::GetId() const
00483 {
00484   return SMESH::VolumeFilter;
00485 }
00486 
00487 //=======================================================================
00488 // name    : SMESHGUI_VolumesFilter::IsNodeFilter
00489 // Purpose : Returns true if filter is intended for nodes
00490 //=======================================================================
00491 bool SMESHGUI_VolumesFilter::IsNodeFilter() const
00492 {
00493   return false;
00494 }