1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // GEOM GEOM_CompoundFilter : filter selector for the viewer
21 // File : GEOM_CompoundFilter.cxx
22 // Author : Roman NIKOLAEV
25 #include "GEOM_CompoundFilter.h"
28 #include <TopTools_MapOfShape.hxx>
29 #include <TopTools_ListOfShape.hxx>
30 #include <TopTools_ListIteratorOfListOfShape.hxx>
31 #include <TopoDS_Iterator.hxx>
35 //=======================================================================
36 // function : GEOM_CompoundFilter
38 //=======================================================================
39 GEOM_CompoundFilter::GEOM_CompoundFilter(SalomeApp_Study* study)
40 : GEOM_SelectionFilter( study )
42 add( TopAbs_COMPOUND );
45 //=======================================================================
46 // function : ~GEOM_CompoundFilter
48 //=======================================================================
49 GEOM_CompoundFilter::~GEOM_CompoundFilter()
53 //=======================================================================
56 //=======================================================================
57 bool GEOM_CompoundFilter::isOk( const SUIT_DataOwner* sOwner) const
59 if(GEOM_SelectionFilter::isOk(sOwner)){
61 GEOM::GEOM_Object_var obj = getObject( sOwner );
63 if ( getShape( obj, shape )){
64 bool subTypes[TopAbs_SHAPE];
65 getInfo(shape,subTypes);
66 QList<int>::const_iterator it;
68 for ( it = myKinds.constBegin(); it != myKinds.constEnd(); ++it )
69 result = result || subTypes[(*it)];
78 //=======================================================================
79 // function : addSubType
81 //=======================================================================
82 void GEOM_CompoundFilter::addSubType( const int type)
84 if(!myKinds.contains(type))
88 //=======================================================================
89 // function : addSubTypes
91 //=======================================================================
92 void GEOM_CompoundFilter::addSubTypes(const QList<int>& kinds)
97 //=======================================================================
98 // function : getInfo()
100 //=======================================================================
101 void GEOM_CompoundFilter::getInfo(const TopoDS_Shape& aShape, bool subTypes[]) const
103 int iType, nbTypes[TopAbs_SHAPE];
104 for (iType = 0; iType < TopAbs_SHAPE; ++iType){
106 subTypes[iType] = false;
109 nbTypes[aShape.ShapeType()]++;
110 TopTools_MapOfShape aMapOfShape;
111 aMapOfShape.Add(aShape);
112 TopTools_ListOfShape aListOfShape;
113 aListOfShape.Append(aShape);
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()]++;
127 for(iType = TopAbs_COMPSOLID; iType < TopAbs_SHAPE; ++iType) {
128 if(nbTypes[iType] > 0) {
129 subTypes[iType] = true;