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