Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_Filter.cxx
1 //  SMESHGUI_Filter : Filters for VTK viewer
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : SMESHGUI_Filter.cxx
25 //  Author : Sergey LITONIN
26 //  Module : SMESH
27
28 #include "SMESHGUI_Filter.h"
29
30 #include <vtkCell.h>
31
32 #include <gp_Vec.hxx>
33 #include <Precision.hxx>
34 #include "SMESH_Actor.h"
35 #include "SMESHGUI.h"
36
37 IMPLEMENT_STANDARD_HANDLE(SMESHGUI_Filter, VTKViewer_Filter)
38 IMPLEMENT_STANDARD_RTTIEXT(SMESHGUI_Filter, VTKViewer_Filter)
39
40 /*
41   Class       : SMESHGUI_Filter
42   Description : Selection filter for VTK viewer. This class aggregate object
43                 of SMESH_Filter class and uses it for verification of criterion
44 */
45
46 //=======================================================================
47 // name    : SMESHGUI_Filter::SMESHGUI_Filter
48 // Purpose : Constructor
49 //=======================================================================
50 SMESHGUI_Filter::SMESHGUI_Filter()
51 {
52   myActor = 0;
53 }
54
55 SMESHGUI_Filter::~SMESHGUI_Filter()
56 {
57 }
58
59 //=======================================================================
60 // name    : SMESHGUI_Filter::IsValid
61 // Purpose : Verify whether entry id satisfies to criterion of the filter
62 //=======================================================================
63 bool SMESHGUI_Filter::IsValid( const int theCellId ) const
64 {
65   if ( myActor == 0 || myPred->_is_nil() )
66     return false;
67
68   SMESH_Actor* anActor = ( SMESH_Actor* )myActor;
69
70   int aMeshId = anActor->GetElemObjId( theCellId );
71
72   return myPred->IsSatisfy( aMeshId );
73 }
74
75 //=======================================================================
76 // name    : SMESHGUI_Filter::SetPredicate
77 // Purpose : Set new pridicate to the filter
78 //=======================================================================
79 void SMESHGUI_Filter::SetPredicate( SMESH::Predicate_ptr thePred )
80 {
81   myPred = thePred;
82 }
83
84 //=======================================================================
85 // name    : SMESHGUI_Filter::GetActor
86 // Purpose : Get actor of the filter
87 //=======================================================================
88 SALOME_Actor* SMESHGUI_Filter::GetActor() const
89 {
90   return myActor;
91 }
92
93 //=======================================================================
94 // name    : SMESHGUI_Filter::SetActor
95 // Purpose : Set new actor
96 //=======================================================================
97 void SMESHGUI_Filter::SetActor( SALOME_Actor* theActor )
98 {
99   if ( myActor == theActor )
100     return;
101   VTKViewer_Filter::SetActor( theActor );
102
103   if ( myActor != 0 && !myPred->_is_nil() )
104   {
105     Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
106     if ( !anIO.IsNull() )
107     {
108       Standard_Boolean aRes = false;
109       SMESH::SMESH_Mesh_ptr aMeshPtr = SMESHGUI::GetSMESHGUI()->ConvertIOinMesh( anIO, aRes );
110       if ( aRes )
111         myPred->SetMesh( aMeshPtr );
112     }
113   }
114 }