Salome HOME
39c11dfbbdcdff6e9403c8b130a671740212444a
[modules/geom.git] / src / GEOMFiltersSelection / GEOM_LogicalFilter.cxx
1 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
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   : GEOM_LogicalFilter.cxx
25 //  Author : Sergey LITONIN
26 //  Module : GEOM
27
28 #include "GEOM_LogicalFilter.hxx"
29
30 /*
31   Class       : GEOM_LogicalFilter
32   Description : Filter for combaining several filters with logical operation (OR or AND)
33 */
34
35 IMPLEMENT_STANDARD_HANDLE( GEOM_LogicalFilter, SALOME_Filter )
36 IMPLEMENT_STANDARD_RTTIEXT( GEOM_LogicalFilter, SALOME_Filter )
37
38 //=======================================================================
39 // name    : GEOM_LogicalFilter::GEOM_LogicalFilter
40 // Purpose : Constructor
41 //=======================================================================
42 GEOM_LogicalFilter::GEOM_LogicalFilter( const GEOM_ListOfFilter& theFilters,
43                                         const int                theLogOp )
44 {
45   myFilters = theFilters;
46   myLogOp = theLogOp;
47 }
48
49 //=======================================================================
50 // name    : GEOM_LogicalFilter::GEOM_LogicalFilter
51 // Purpose : Constructor
52 //=======================================================================
53 GEOM_LogicalFilter::GEOM_LogicalFilter( const Handle(SALOME_Filter)& theFilter,
54                                         const int                    theLogOp )
55 {
56   myFilters.Append( theFilter );
57   myLogOp = theLogOp;
58 }
59
60 //=======================================================================
61 // name    : GEOM_LogicalFilter::~GEOM_LogicalFilter
62 // Purpose : Destructor
63 //=======================================================================
64 GEOM_LogicalFilter::~GEOM_LogicalFilter()
65 {
66 }
67
68 //=======================================================================
69 // name    : GEOM_LogicalFilter::IsOk
70 // Purpose : Verify validity of entry object
71 //=======================================================================
72 Standard_Boolean GEOM_LogicalFilter::IsOk( const Handle(SALOME_InteractiveObject)& theIO ) const
73 {
74   GEOM_ListOfFilter::Iterator anIter( myFilters );
75   for ( ; anIter.More(); anIter.Next() )
76   {
77     Handle(SALOME_Filter) aFilter = anIter.Value();
78     if ( !aFilter.IsNull() )
79     {
80       if ( myLogOp == LO_OR && anIter.Value()->IsOk( theIO ) )
81         return true;
82       if ( myLogOp == LO_AND && !anIter.Value()->IsOk( theIO ) )
83         return false;
84       if ( myLogOp == LO_NOT )
85         return !anIter.Value()->IsOk( theIO );
86     }
87   }
88
89   return myLogOp == LO_OR ? false : true;
90 }
91
92 //=======================================================================
93 // name    : GEOM_LogicalFilter::SetFilters
94 // Purpose : Set new list of filters. Old wilters are removed
95 //=======================================================================
96 void GEOM_LogicalFilter::SetFilters( const GEOM_ListOfFilter& theFilters )
97 {
98   myFilters = theFilters;
99 }
100
101 //=======================================================================
102 // name    : GEOM_LogicalFilter::SetLogOp
103 // Purpose : Set logical operation
104 //=======================================================================
105 void GEOM_LogicalFilter::SetLogOp( const int theLogOp )
106 {
107   myLogOp = theLogOp;
108 }
109
110 //=======================================================================
111 // name    : GEOM_LogicalFilter::GetFilters
112 // Purpose : Get list of filters
113 //=======================================================================
114 const GEOM_ListOfFilter& GEOM_LogicalFilter::GetFilters() const
115 {
116   return myFilters;
117 }
118
119 //=======================================================================
120 // name    : GEOM_LogicalFilter::GetLogOp
121 // Purpose : Get logical operation
122 //=======================================================================
123 int GEOM_LogicalFilter::GetLogOp() const
124 {
125   return myLogOp;
126 }
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161