Salome HOME
0020145: EDF 666 SMESH: Modifications of GEOM groups are not taken into account
[modules/smesh.git] / src / SMESHFiltersSelection / SMESH_LogicalFilter.cxx
1 //  Copyright (C) 2007-2008  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.
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 //  File   : SMESH_LogicalFilter.cxx
23 //  Module : SMESH
24 //
25 #include "SMESH_LogicalFilter.hxx"
26
27 //=======================================================================
28 // name    : SMESH_LogicalFilter::SMESH_LogicalFilter
29 // Purpose : Constructor
30 //=======================================================================
31 SMESH_LogicalFilter::SMESH_LogicalFilter (const QPtrList<SUIT_SelectionFilter>& theFilters,
32                                           const int                             theLogOp)
33 {
34   setFilters(theFilters); 
35   setOperation(theLogOp);
36 }
37
38 //=======================================================================
39 // name    : SMESH_LogicalFilter::~SMESH_LogicalFilter
40 // Purpose : Destructor
41 //=======================================================================
42 SMESH_LogicalFilter::~SMESH_LogicalFilter()
43 {
44 }
45
46 //=======================================================================
47 // name    : SMESH_LogicalFilter::IsOk
48 // Purpose : Verify validity of entry object
49 //=======================================================================
50 bool SMESH_LogicalFilter::isOk (const SUIT_DataOwner* owner) const
51 {
52   bool res = true;
53   QPtrListIterator<SUIT_SelectionFilter> it (myFilters);
54   SUIT_SelectionFilter* filter;
55   for (; ((filter = it.current()) != 0) && res; ++it)
56   {
57     if (myOperation == LO_OR && filter->isOk(owner))
58       return true;
59     if (myOperation == LO_AND && !filter->isOk(owner))
60       return false;
61     if (myOperation == LO_NOT)
62       return !filter->isOk(owner);
63   }
64
65   return (myOperation != LO_OR);
66 }
67
68 //=======================================================================
69 // name    : SMESH_LogicalFilter::setFilters
70 // Purpose : Set new list of filters. Old wilters are removed
71 //=======================================================================
72 void SMESH_LogicalFilter::setFilters (const QPtrList<SUIT_SelectionFilter>& theFilters)
73 {
74   myFilters = theFilters;
75 }
76
77 //=======================================================================
78 // name    : SMESH_LogicalFilter::setOperation
79 // Purpose : Set logical operation
80 //=======================================================================
81 void SMESH_LogicalFilter::setOperation (const int theLogOp)
82 {
83   myOperation = theLogOp;
84 }
85
86 //=======================================================================
87 // name    : SMESH_LogicalFilter::getFilters
88 // Purpose : Get list of filters
89 //=======================================================================
90 const QPtrList<SUIT_SelectionFilter> SMESH_LogicalFilter::getFilters() const
91 {
92   return myFilters;
93 }
94
95 //=======================================================================
96 // name    : SMESH_LogicalFilter::getOperation
97 // Purpose : Get logical operation
98 //=======================================================================
99 int SMESH_LogicalFilter::getOperation() const
100 {
101   return myOperation;
102 }