Salome HOME
1f44d866dc543725f99a9977bf4240f43be61c3a
[modules/geom.git] / src / MeasureGUI / MeasureGUI_DimensionFilter.cxx
1 // Copyright (C) 2007-2023  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_RTTIEXT(MeasureGUI_DimensionFilter, SelectMgr_Filter)
36
37 //=======================================================================
38 // function : Constructor
39 // purpose  : 
40 //=======================================================================
41 MeasureGUI_DimensionFilter::MeasureGUI_DimensionFilter( const Handle(AIS_InteractiveObject)& theIO )
42 : SelectMgr_Filter(), 
43   myFilterIO( theIO ),
44   myFilterEntry(),
45   myFilterId( 0 ),
46   myIsFilterIO( Standard_True ),
47   myIsFilterEntry( Standard_False ),
48   myIsFilterId( Standard_False )
49 {
50 }
51
52 //=======================================================================
53 // function : Constructor
54 // purpose  : 
55 //=======================================================================
56 MeasureGUI_DimensionFilter::MeasureGUI_DimensionFilter( const int theId )
57 : SelectMgr_Filter(), 
58   myFilterIO(),
59   myFilterEntry(),
60   myFilterId( theId ),
61   myIsFilterIO( Standard_False ),
62   myIsFilterEntry( Standard_False ),
63   myIsFilterId( Standard_True )
64 {
65 }
66
67 //=======================================================================
68 // function : Constructor
69 // purpose  : 
70 //=======================================================================
71 MeasureGUI_DimensionFilter::MeasureGUI_DimensionFilter( const std::string& theEntry )
72 : SelectMgr_Filter(),
73   myFilterIO( NULL ),
74   myFilterEntry( theEntry ),
75   myFilterId( 0 ),
76   myIsFilterIO( Standard_False ),
77   myIsFilterEntry( Standard_True ),
78   myIsFilterId( Standard_False )
79 {
80 }
81
82 //=======================================================================
83 // function : Constructor
84 // purpose  : 
85 //=======================================================================
86 MeasureGUI_DimensionFilter::MeasureGUI_DimensionFilter( const std::string& theEntry, const int theId )
87 : SelectMgr_Filter(),
88   myFilterIO( NULL ),
89   myFilterEntry( theEntry ),
90   myFilterId( theId ),
91   myIsFilterIO( Standard_False ),
92   myIsFilterEntry( Standard_True ),
93   myIsFilterId( Standard_True )
94 {
95 }
96
97 //=======================================================================
98 // function : SetFilterIO
99 // purpose  : 
100 //=======================================================================
101 void MeasureGUI_DimensionFilter::SetFilterIO( const Handle(AIS_InteractiveObject)& theIO )
102 {
103   myFilterIO = theIO;
104   myIsFilterIO = Standard_True;
105 }
106
107 //=======================================================================
108 // function : SetFilterEntry
109 // purpose  : 
110 //=======================================================================
111 void MeasureGUI_DimensionFilter::SetFilterEntry( const std::string& theEntry )
112 {
113   myFilterEntry = theEntry;
114   myIsFilterEntry = Standard_True;
115 }
116
117 //=======================================================================
118 // function : SetFilterId
119 // purpose  : 
120 //=======================================================================
121 void MeasureGUI_DimensionFilter::SetFilterId( const int theId )
122 {
123   myFilterId = theId;
124   myIsFilterId = Standard_True;
125 }
126
127 //=======================================================================
128 // function : IsOk
129 // purpose  : 
130 //=======================================================================
131 Standard_Boolean MeasureGUI_DimensionFilter::IsOk( const Handle(SelectMgr_EntityOwner)& theEntity ) const
132 {
133   Handle(AIS_InteractiveObject) anAIS = Handle(AIS_InteractiveObject)::DownCast( theEntity->Selectable() );
134
135   if ( anAIS.IsNull() || !anAIS->HasOwner() )
136   {
137     return Standard_False;
138   }
139   
140   if ( !anAIS->IsKind( STANDARD_TYPE( AIS_LengthDimension ) )
141     && !anAIS->IsKind( STANDARD_TYPE( AIS_DiameterDimension ) )
142     && !anAIS->IsKind( STANDARD_TYPE( AIS_AngleDimension ) ) )
143   {
144     return Standard_False;
145   }
146
147   if ( myIsFilterIO )
148   {
149     if ( anAIS != myFilterIO )
150     {
151       return Standard_False;
152     }
153   }
154
155   if ( myIsFilterEntry )
156   {
157     Handle(SALOME_InteractiveObject) anIO = Handle(SALOME_InteractiveObject)::DownCast( anAIS->GetOwner() );
158     if ( anIO.IsNull() )
159     {
160       return Standard_False;
161     }
162
163     if ( std::string( anIO->getEntry() ) != myFilterEntry )
164     {
165       return Standard_False;
166     }
167   }
168
169   if ( myIsFilterId )
170   {
171     Handle(GEOM_AISLength) aLength = Handle(GEOM_AISLength)::DownCast( anAIS );
172     if ( !aLength.IsNull() && aLength->GetId() != myFilterId )
173     {
174       return Standard_False;
175     }
176
177     Handle(GEOM_AISDiameter) aDiameter = Handle(GEOM_AISDiameter)::DownCast( anAIS );
178     if ( !aDiameter.IsNull() && aDiameter->GetId() != myFilterId )
179     {
180       return Standard_False;
181     }
182
183     Handle(GEOM_AISAngle) anAngle = Handle(GEOM_AISAngle)::DownCast( anAIS );
184     if ( !anAngle.IsNull() && anAngle->GetId() != myFilterId )
185     {
186       return Standard_False;
187     }
188   }
189
190   return Standard_True;
191 }