Salome HOME
Mantis issue 0020706: EDF 1263 GEOM: Suppress faces does notremove faces and adds...
[modules/geom.git] / src / GEOMFiltersSelection / GEOM_CompoundFilter.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 //  GEOM GEOM_CompoundFilter : filter selector for the viewer
23 //  File   : GEOM_CompoundFilter.cxx
24 //  Author : Roman NIKOLAEV
25 //  Module : GEOM
26 //
27 #include "GEOM_CompoundFilter.h"
28
29 // OCCT Includes
30 #include <TopTools_MapOfShape.hxx>
31 #include <TopTools_ListOfShape.hxx>
32 #include <TopTools_ListIteratorOfListOfShape.hxx>
33 #include <TopoDS_Iterator.hxx>
34
35
36
37 //=======================================================================
38 // function : GEOM_CompoundFilter
39 // purpose  : 
40 //=======================================================================
41 GEOM_CompoundFilter::GEOM_CompoundFilter(SalomeApp_Study* study)
42 : GEOM_SelectionFilter( study )
43 {
44   add( TopAbs_COMPOUND );
45 }
46
47 //=======================================================================
48 // function : ~GEOM_CompoundFilter
49 // purpose  : 
50 //=======================================================================
51 GEOM_CompoundFilter::~GEOM_CompoundFilter()
52 {
53 }
54
55 //=======================================================================
56 // function : isOk
57 // purpose  : 
58 //=======================================================================
59 bool GEOM_CompoundFilter::isOk( const SUIT_DataOwner* sOwner) const
60 {
61   if(GEOM_SelectionFilter::isOk(sOwner)){
62
63     GEOM::GEOM_Object_var obj = getObject( sOwner );
64     TopoDS_Shape shape;
65     if ( getShape( obj, shape )){
66       bool subTypes[TopAbs_SHAPE];
67       getInfo(shape,subTypes);
68       QList<int>::const_iterator it;
69       bool result = false;
70       for ( it = myKinds.constBegin(); it != myKinds.constEnd(); ++it )
71         result = result || subTypes[(*it)];
72       
73       return result;
74     }
75   }
76   return false;
77 }
78
79
80 //=======================================================================
81 // function : addSubType
82 // purpose  : 
83 //=======================================================================
84 void GEOM_CompoundFilter::addSubType( const int type)
85 {
86   if(!myKinds.contains(type))
87     myKinds.append(type);
88 }
89
90 //=======================================================================
91 // function : addSubTypes
92 // purpose  : 
93 //=======================================================================
94 void GEOM_CompoundFilter::addSubTypes(const QList<int>& kinds)
95 {
96   myKinds = kinds;     
97 }
98
99 //=======================================================================
100 // function : getInfo()
101 // purpose  : 
102 //=======================================================================
103 void GEOM_CompoundFilter::getInfo(const TopoDS_Shape& aShape, bool subTypes[]) const
104 {
105   int iType, nbTypes[TopAbs_SHAPE];
106   for (iType = 0; iType < TopAbs_SHAPE; ++iType){
107     nbTypes[iType] = 0;
108     subTypes[iType] = false;
109   }
110
111   nbTypes[aShape.ShapeType()]++;
112   TopTools_MapOfShape aMapOfShape;
113   aMapOfShape.Add(aShape);
114   TopTools_ListOfShape aListOfShape;
115   aListOfShape.Append(aShape);
116   
117   TopTools_ListIteratorOfListOfShape itL (aListOfShape);
118   for (; itL.More(); itL.Next()) {
119     TopoDS_Iterator it (itL.Value());
120     for (; it.More(); it.Next()) {
121       TopoDS_Shape s = it.Value();
122       if (aMapOfShape.Add(s)) {
123         aListOfShape.Append(s);
124         nbTypes[s.ShapeType()]++;
125       }
126     }
127   }
128   
129   for(iType = TopAbs_COMPSOLID; iType < TopAbs_SHAPE; ++iType) {
130     if(nbTypes[iType] > 0) {
131       subTypes[iType] = true;
132       break;
133     }
134   }
135 }