Salome HOME
cf5b4a2b3c8459f000aafc423fece0141e7c5d3b
[modules/geom.git] / src / GEOMFiltersSelection / GEOM_CompoundFilter.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  GEOM GEOM_CompoundFilter : filter selector for the viewer
21 //  File   : GEOM_CompoundFilter.cxx
22 //  Author : Roman NIKOLAEV
23 //  Module : GEOM
24 //
25 #include "GEOM_CompoundFilter.h"
26
27 // OCCT Includes
28 #include <TopTools_MapOfShape.hxx>
29 #include <TopTools_ListOfShape.hxx>
30 #include <TopTools_ListIteratorOfListOfShape.hxx>
31 #include <TopoDS_Iterator.hxx>
32
33
34
35 //=======================================================================
36 // function : GEOM_CompoundFilter
37 // purpose  : 
38 //=======================================================================
39 GEOM_CompoundFilter::GEOM_CompoundFilter(SalomeApp_Study* study)
40 : GEOM_SelectionFilter( study )
41 {
42   add( TopAbs_COMPOUND );
43 }
44
45 //=======================================================================
46 // function : ~GEOM_CompoundFilter
47 // purpose  : 
48 //=======================================================================
49 GEOM_CompoundFilter::~GEOM_CompoundFilter()
50 {
51 }
52
53 //=======================================================================
54 // function : isOk
55 // purpose  : 
56 //=======================================================================
57 bool GEOM_CompoundFilter::isOk( const SUIT_DataOwner* sOwner) const
58 {
59   if(GEOM_SelectionFilter::isOk(sOwner)){
60
61     GEOM::GEOM_Object_var obj = getObject( sOwner );
62     TopoDS_Shape shape;
63     if ( getShape( obj, shape )){
64       bool subTypes[TopAbs_SHAPE];
65       getInfo(shape,subTypes);
66       QList<int>::const_iterator it;
67       bool result = false;
68       for ( it = myKinds.constBegin(); it != myKinds.constEnd(); ++it )
69         result = result || subTypes[(*it)];
70       
71       return result;
72     }
73   }
74   return false;
75 }
76
77
78 //=======================================================================
79 // function : addSubType
80 // purpose  : 
81 //=======================================================================
82 void GEOM_CompoundFilter::addSubType( const int type)
83 {
84   if(!myKinds.contains(type))
85     myKinds.append(type);
86 }
87
88 //=======================================================================
89 // function : addSubTypes
90 // purpose  : 
91 //=======================================================================
92 void GEOM_CompoundFilter::addSubTypes(const QList<int>& kinds)
93 {
94   myKinds = kinds;     
95 }
96
97 //=======================================================================
98 // function : getInfo()
99 // purpose  : 
100 //=======================================================================
101 void GEOM_CompoundFilter::getInfo(const TopoDS_Shape& aShape, bool subTypes[]) const
102 {
103   int iType, nbTypes[TopAbs_SHAPE];
104   for (iType = 0; iType < TopAbs_SHAPE; ++iType){
105     nbTypes[iType] = 0;
106     subTypes[iType] = false;
107   }
108
109   nbTypes[aShape.ShapeType()]++;
110   TopTools_MapOfShape aMapOfShape;
111   aMapOfShape.Add(aShape);
112   TopTools_ListOfShape aListOfShape;
113   aListOfShape.Append(aShape);
114   
115   TopTools_ListIteratorOfListOfShape itL (aListOfShape);
116   for (; itL.More(); itL.Next()) {
117     TopoDS_Iterator it (itL.Value());
118     for (; it.More(); it.Next()) {
119       TopoDS_Shape s = it.Value();
120       if (aMapOfShape.Add(s)) {
121         aListOfShape.Append(s);
122         nbTypes[s.ShapeType()]++;
123       }
124     }
125   }
126   
127   for(iType = TopAbs_COMPSOLID; iType < TopAbs_SHAPE; ++iType) {
128     if(nbTypes[iType] > 0) {
129       subTypes[iType] = true;
130       break;
131     }
132   }
133 }