Back to index

salome-geom  6.5.0
GEOM_CompoundFilter.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 //  GEOM GEOM_CompoundFilter : filter selector for the viewer
00021 //  File   : GEOM_CompoundFilter.cxx
00022 //  Author : Roman NIKOLAEV
00023 //  Module : GEOM
00024 //
00025 #include "GEOM_CompoundFilter.h"
00026 
00027 // OCCT Includes
00028 #include <TopTools_MapOfShape.hxx>
00029 #include <TopTools_ListOfShape.hxx>
00030 #include <TopTools_ListIteratorOfListOfShape.hxx>
00031 #include <TopoDS_Iterator.hxx>
00032 
00033 
00034 
00035 //=======================================================================
00036 // function : GEOM_CompoundFilter
00037 // purpose  : 
00038 //=======================================================================
00039 GEOM_CompoundFilter::GEOM_CompoundFilter(SalomeApp_Study* study)
00040 : GEOM_SelectionFilter( study )
00041 {
00042   add( TopAbs_COMPOUND );
00043 }
00044 
00045 //=======================================================================
00046 // function : ~GEOM_CompoundFilter
00047 // purpose  : 
00048 //=======================================================================
00049 GEOM_CompoundFilter::~GEOM_CompoundFilter()
00050 {
00051 }
00052 
00053 //=======================================================================
00054 // function : isOk
00055 // purpose  : 
00056 //=======================================================================
00057 bool GEOM_CompoundFilter::isOk( const SUIT_DataOwner* sOwner) const
00058 {
00059   if(GEOM_SelectionFilter::isOk(sOwner)){
00060 
00061     GEOM::GEOM_Object_var obj = getObject( sOwner );
00062     TopoDS_Shape shape;
00063     if ( getShape( obj, shape )){
00064       bool subTypes[TopAbs_SHAPE];
00065       getInfo(shape,subTypes);
00066       QList<int>::const_iterator it;
00067       bool result = false;
00068       for ( it = myKinds.constBegin(); it != myKinds.constEnd(); ++it )
00069         result = result || subTypes[(*it)];
00070       
00071       return result;
00072     }
00073   }
00074   return false;
00075 }
00076 
00077 
00078 //=======================================================================
00079 // function : addSubType
00080 // purpose  : 
00081 //=======================================================================
00082 void GEOM_CompoundFilter::addSubType( const int type)
00083 {
00084   if(!myKinds.contains(type))
00085     myKinds.append(type);
00086 }
00087 
00088 //=======================================================================
00089 // function : addSubTypes
00090 // purpose  : 
00091 //=======================================================================
00092 void GEOM_CompoundFilter::addSubTypes(const QList<int>& kinds)
00093 {
00094   myKinds = kinds;     
00095 }
00096 
00097 //=======================================================================
00098 // function : getInfo()
00099 // purpose  : 
00100 //=======================================================================
00101 void GEOM_CompoundFilter::getInfo(const TopoDS_Shape& aShape, bool subTypes[]) const
00102 {
00103   int iType, nbTypes[TopAbs_SHAPE];
00104   for (iType = 0; iType < TopAbs_SHAPE; ++iType){
00105     nbTypes[iType] = 0;
00106     subTypes[iType] = false;
00107   }
00108 
00109   nbTypes[aShape.ShapeType()]++;
00110   TopTools_MapOfShape aMapOfShape;
00111   aMapOfShape.Add(aShape);
00112   TopTools_ListOfShape aListOfShape;
00113   aListOfShape.Append(aShape);
00114   
00115   TopTools_ListIteratorOfListOfShape itL (aListOfShape);
00116   for (; itL.More(); itL.Next()) {
00117     TopoDS_Iterator it (itL.Value());
00118     for (; it.More(); it.Next()) {
00119       TopoDS_Shape s = it.Value();
00120       if (aMapOfShape.Add(s)) {
00121         aListOfShape.Append(s);
00122         nbTypes[s.ShapeType()]++;
00123       }
00124     }
00125   }
00126   
00127   for(iType = TopAbs_COMPSOLID; iType < TopAbs_SHAPE; ++iType) {
00128     if(nbTypes[iType] > 0) {
00129       subTypes[iType] = true;
00130       break;
00131     }
00132   }
00133 }