Salome HOME
1495c9636915ca6db4cbc318b625370d64e97bf6
[modules/smesh.git] / src / SMESHFiltersSelection / SMESH_LogicalFilter.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
8 //
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : SMESH_LogicalFilter.cxx
21 //  Module : SMESH
22
23 #include "SMESH_LogicalFilter.hxx"
24
25 //=======================================================================
26 // name    : SMESH_LogicalFilter::SMESH_LogicalFilter
27 // Purpose : Constructor
28 //=======================================================================
29 SMESH_LogicalFilter::SMESH_LogicalFilter (const QList<SUIT_SelectionFilter*>& theFilters,
30                                           const int                             theLogOp)
31 {
32   setFilters(theFilters);
33   setOperation(theLogOp);
34 }
35
36 //=======================================================================
37 // name    : SMESH_LogicalFilter::~SMESH_LogicalFilter
38 // Purpose : Destructor
39 //=======================================================================
40 SMESH_LogicalFilter::~SMESH_LogicalFilter()
41 {
42 }
43
44 //=======================================================================
45 // name    : SMESH_LogicalFilter::IsOk
46 // Purpose : Verify validity of entry object
47 //=======================================================================
48 bool SMESH_LogicalFilter::isOk (const SUIT_DataOwner* owner) const
49 {
50   bool res = true;
51   for ( QList<SUIT_SelectionFilter*>::const_iterator it = myFilters.begin(); it != myFilters.end() && res; ++it )
52   {
53     SUIT_SelectionFilter* filter = *it;
54     if (myOperation == LO_OR && filter->isOk(owner))
55       return true;
56     if (myOperation == LO_AND && !filter->isOk(owner))
57       return false;
58     if (myOperation == LO_NOT)
59       return !filter->isOk(owner);
60   }
61
62   return (myOperation != LO_OR);
63 }
64
65 //=======================================================================
66 // name    : SMESH_LogicalFilter::setFilters
67 // Purpose : Set new list of filters. Old wilters are removed
68 //=======================================================================
69 void SMESH_LogicalFilter::setFilters (const QList<SUIT_SelectionFilter*>& theFilters)
70 {
71   myFilters = theFilters;
72 }
73
74 //=======================================================================
75 // name    : SMESH_LogicalFilter::setOperation
76 // Purpose : Set logical operation
77 //=======================================================================
78 void SMESH_LogicalFilter::setOperation (const int theLogOp)
79 {
80   myOperation = theLogOp;
81 }
82
83 //=======================================================================
84 // name    : SMESH_LogicalFilter::getFilters
85 // Purpose : Get list of filters
86 //=======================================================================
87 const QList<SUIT_SelectionFilter*> SMESH_LogicalFilter::getFilters() const
88 {
89   return myFilters;
90 }
91
92 //=======================================================================
93 // name    : SMESH_LogicalFilter::getOperation
94 // Purpose : Get logical operation
95 //=======================================================================
96 int SMESH_LogicalFilter::getOperation() const
97 {
98   return myOperation;
99 }