Back to index

salome-smesh  6.5.0
SMESH_LogicalFilter.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : SMESH_LogicalFilter.cxx
00024 //  Module : SMESH
00025 //
00026 #include "SMESH_LogicalFilter.hxx"
00027 
00028 //=======================================================================
00029 // name    : SMESH_LogicalFilter::SMESH_LogicalFilter
00030 // Purpose : Constructor
00031 //=======================================================================
00032 SMESH_LogicalFilter::SMESH_LogicalFilter (const QList<SUIT_SelectionFilter*>& theFilters,
00033                                           const int                           theLogOp,
00034                                           bool                                takeOwnership)
00035   : myOwnership( takeOwnership )
00036 {
00037   setFilters(theFilters);
00038   setOperation(theLogOp);
00039 }
00040 
00041 //=======================================================================
00042 // name    : SMESH_LogicalFilter::~SMESH_LogicalFilter
00043 // Purpose : Destructor
00044 //=======================================================================
00045 SMESH_LogicalFilter::~SMESH_LogicalFilter()
00046 {
00047   deleteFilters();
00048 }
00049 
00050 //=======================================================================
00051 // name    : SMESH_LogicalFilter::IsOk
00052 // Purpose : Verify validity of entry object
00053 //=======================================================================
00054 bool SMESH_LogicalFilter::isOk (const SUIT_DataOwner* owner) const
00055 {
00056   SUIT_SelectionFilter* filter;
00057   foreach( filter, myFilters )
00058   {
00059     if (myOperation == LO_OR && filter->isOk(owner))
00060       return true;
00061     if (myOperation == LO_AND && !filter->isOk(owner))
00062       return false;
00063     if (myOperation == LO_NOT)
00064       return !filter->isOk(owner);
00065   }
00066 
00067   return (myOperation != LO_OR);
00068 }
00069 
00070 //=======================================================================
00071 // name    : SMESH_LogicalFilter::setFilters
00072 // Purpose : Set new list of filters. Old wilters are removed
00073 //=======================================================================
00074 void SMESH_LogicalFilter::setFilters (const QList<SUIT_SelectionFilter*>& theFilters)
00075 {
00076   deleteFilters();
00077   myFilters = theFilters;
00078 }
00079 
00080 //=======================================================================
00081 // name    : SMESH_LogicalFilter::setOperation
00082 // Purpose : Set logical operation
00083 //=======================================================================
00084 void SMESH_LogicalFilter::setOperation (const int theLogOp)
00085 {
00086   myOperation = theLogOp;
00087 }
00088 
00089 //=======================================================================
00090 // name    : SMESH_LogicalFilter::getFilters
00091 // Purpose : Get list of filters
00092 //=======================================================================
00093 const QList<SUIT_SelectionFilter*> SMESH_LogicalFilter::getFilters() const
00094 {
00095   return myFilters;
00096 }
00097 
00098 //=======================================================================
00099 // name    : SMESH_LogicalFilter::getOperation
00100 // Purpose : Get logical operation
00101 //=======================================================================
00102 int SMESH_LogicalFilter::getOperation() const
00103 {
00104   return myOperation;
00105 }
00106 //================================================================================
00110 //================================================================================
00111 
00112 void SMESH_LogicalFilter::deleteFilters()
00113 {
00114   if ( myOwnership )
00115   {
00116     SUIT_SelectionFilter* filter;
00117     foreach( filter, myFilters )
00118       delete filter;
00119   }
00120 }