Salome HOME
c9ccc5c62fb7bd5fbe61e92c85fcd264c7986f80
[modules/geom.git] / src / MeasureGUI / MeasureGUI_DimensionFilter.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : MeasureGUI_DimensionFilter.cxx
25 // Author : Anton POLETAEV, Open CASCADE S.A.S.
26
27 #include "MeasureGUI_DimensionFilter.h"
28
29 // GEOM includes
30 #include <GEOM_AISDimension.hxx>
31
32 // SALOME includes
33 #include <SALOME_InteractiveObject.hxx>
34
35 IMPLEMENT_STANDARD_HANDLE (MeasureGUI_DimensionFilter, SelectMgr_Filter)
36 IMPLEMENT_STANDARD_RTTIEXT(MeasureGUI_DimensionFilter, SelectMgr_Filter)
37
38 //=======================================================================
39 // function : Constructor
40 // purpose  : 
41 //=======================================================================
42 MeasureGUI_DimensionFilter::MeasureGUI_DimensionFilter( const Handle(AIS_InteractiveObject)& theIO )
43 : SelectMgr_Filter(), 
44   myFilterIO( theIO ),
45   myFilterEntry(),
46   myFilterId( 0 ),
47   myIsFilterIO( Standard_True ),
48   myIsFilterEntry( Standard_False ),
49   myIsFilterId( Standard_False )
50 {
51 }
52
53 //=======================================================================
54 // function : Constructor
55 // purpose  : 
56 //=======================================================================
57 MeasureGUI_DimensionFilter::MeasureGUI_DimensionFilter( const int theId )
58 : SelectMgr_Filter(), 
59   myFilterIO(),
60   myFilterEntry(),
61   myFilterId( theId ),
62   myIsFilterIO( Standard_False ),
63   myIsFilterEntry( Standard_False ),
64   myIsFilterId( Standard_True )
65 {
66 }
67
68 //=======================================================================
69 // function : Constructor
70 // purpose  : 
71 //=======================================================================
72 MeasureGUI_DimensionFilter::MeasureGUI_DimensionFilter( const std::string& theEntry )
73 : SelectMgr_Filter(),
74   myFilterIO( NULL ),
75   myFilterEntry( theEntry ),
76   myFilterId( 0 ),
77   myIsFilterIO( Standard_False ),
78   myIsFilterEntry( Standard_True ),
79   myIsFilterId( Standard_False )
80 {
81 }
82
83 //=======================================================================
84 // function : Constructor
85 // purpose  : 
86 //=======================================================================
87 MeasureGUI_DimensionFilter::MeasureGUI_DimensionFilter( const std::string& theEntry, const int theId )
88 : SelectMgr_Filter(),
89   myFilterIO( NULL ),
90   myFilterEntry( theEntry ),
91   myFilterId( theId ),
92   myIsFilterIO( Standard_False ),
93   myIsFilterEntry( Standard_True ),
94   myIsFilterId( Standard_True )
95 {
96 }
97
98 //=======================================================================
99 // function : SetFilterIO
100 // purpose  : 
101 //=======================================================================
102 void MeasureGUI_DimensionFilter::SetFilterIO( const Handle(AIS_InteractiveObject)& theIO )
103 {
104   myFilterIO = theIO;
105   myIsFilterIO = Standard_True;
106 }
107
108 //=======================================================================
109 // function : SetFilterEntry
110 // purpose  : 
111 //=======================================================================
112 void MeasureGUI_DimensionFilter::SetFilterEntry( const std::string& theEntry )
113 {
114   myFilterEntry = theEntry;
115   myIsFilterEntry = Standard_True;
116 }
117
118 //=======================================================================
119 // function : SetFilterId
120 // purpose  : 
121 //=======================================================================
122 void MeasureGUI_DimensionFilter::SetFilterId( const int theId )
123 {
124   myFilterId = theId;
125   myIsFilterId = Standard_True;
126 }
127
128 //=======================================================================
129 // function : IsOk
130 // purpose  : 
131 //=======================================================================
132 Standard_Boolean MeasureGUI_DimensionFilter::IsOk( const Handle(SelectMgr_EntityOwner)& theEntity ) const
133 {
134   Handle(AIS_InteractiveObject) anAIS = Handle(AIS_InteractiveObject)::DownCast( theEntity->Selectable() );
135
136   if ( anAIS.IsNull() || !anAIS->HasOwner() )
137   {
138     return Standard_False;
139   }
140   
141   if ( !anAIS->IsKind( STANDARD_TYPE( AIS_LengthDimension ) )
142     && !anAIS->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) )
143     && !anAIS->IsKind( STANDARD_TYPE( AIS_AngleDimension ) ) )
144   {
145     return Standard_False;
146   }
147
148   if ( myIsFilterIO )
149   {
150     if ( anAIS != myFilterIO )
151     {
152       return Standard_False;
153     }
154   }
155
156   if ( myIsFilterEntry )
157   {
158     Handle(SALOME_InteractiveObject) anIO = Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
159     if ( anIO.IsNull() )
160     {
161       return Standard_False;
162     }
163
164     if ( std::string( anIO->getEntry() ) != myFilterEntry )
165     {
166       return Standard_False;
167     }
168   }
169
170   if ( myIsFilterId )
171   {
172     Handle(GEOM_AISLength) aLength = Handle(GEOM_AISLength)::DownCast( anAIS );
173     if ( !aLength.IsNull() && aLength->GetId() != myFilterId )
174     {
175       return Standard_False;
176     }
177
178     Handle(GEOM_AISDiameter) aDiameter = Handle(GEOM_AISDiameter)::DownCast( anAIS );
179     if ( !aDiameter.IsNull() && aDiameter->GetId() != myFilterId )
180     {
181       return Standard_False;
182     }
183
184     Handle(GEOM_AISAngle) anAngle = Handle(GEOM_AISAngle)::DownCast( anAIS );
185     if ( !anAngle.IsNull() && anAngle->GetId() != myFilterId )
186     {
187       return Standard_False;
188     }
189   }
190
191   return Standard_True;
192 }