1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_NumberFilter.cxx
25 // Author : Sergey LITONIN
28 #include "SMESH_NumberFilter.hxx"
30 #include "TopTools_MapOfShape.hxx"
31 #include "TopExp_Explorer.hxx"
32 #include "SALOME_InteractiveObject.hxx"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
38 Class : SMESH_NumberFilter
39 Description : Filter for geom objects.
40 Filter geom objects by number of subshapes of the given type
43 IMPLEMENT_STANDARD_HANDLE( SMESH_NumberFilter, SALOME_TypeFilter )
44 IMPLEMENT_STANDARD_RTTIEXT( SMESH_NumberFilter, SALOME_TypeFilter )
46 //=======================================================================
47 // name : SMESH_NumberFilter::SMESH_NumberFilter
48 // Purpose : Constructor
49 //=======================================================================
50 SMESH_NumberFilter::SMESH_NumberFilter( const char* theKind,
51 const TopAbs_ShapeEnum theSubShapeType,
53 const TopAbs_ShapeEnum theShapeType,
54 GEOM::GEOM_Object_ptr theMainObj,
55 const bool theIsClosedOnly )
56 : SALOME_TypeFilter( (char*)theKind )
58 mySubShapeType = theSubShapeType;
60 myIsClosedOnly = theIsClosedOnly;
61 myShapeTypes.Add( theShapeType );
62 myMainObj = GEOM::GEOM_Object::_duplicate( theMainObj );
65 //=======================================================================
66 // name : SMESH_NumberFilter::SMESH_NumberFilter
67 // Purpose : Constructor
68 //=======================================================================
69 SMESH_NumberFilter::SMESH_NumberFilter( const char* theKind,
70 const TopAbs_ShapeEnum theSubShapeType,
72 const TColStd_MapOfInteger& theShapeTypes,
73 GEOM::GEOM_Object_ptr theMainObj,
74 const bool theIsClosedOnly )
75 : SALOME_TypeFilter( (char*)theKind )
77 mySubShapeType = theSubShapeType;
79 myIsClosedOnly = theIsClosedOnly;
80 myShapeTypes = theShapeTypes;
81 myMainObj = GEOM::GEOM_Object::_duplicate( theMainObj );
84 SMESH_NumberFilter::~SMESH_NumberFilter()
88 //=======================================================================
89 // name : SMESH_NumberFilter::SMESH_NumberFilter
90 // Purpose : Verify validity of entry object
91 //=======================================================================
92 Standard_Boolean SMESH_NumberFilter::IsOk( const Handle(SALOME_InteractiveObject)& theObj ) const
94 if ( theObj.IsNull() || !SALOME_TypeFilter::IsOk( theObj ) )
97 // Get geom object from IO
98 GEOM::GEOM_Object_var aGeomObj = getGeom( theObj );
99 if ( aGeomObj->_is_nil() )
102 // Get shape from geom object and verify its parameters
104 if ( !GEOMBase::GetShape( aGeomObj, aShape ) ||
106 !myShapeTypes.Contains( aShape.ShapeType() ) ||
107 myIsClosedOnly && aShape.ShapeType() == TopAbs_SHELL && !aShape.Closed() )
110 // Verify whether shape of entry object is sub-shape of myMainObj
111 if ( !myMainObj->_is_nil() )
113 TopoDS_Shape aMainShape;
114 if ( !GEOMBase::GetShape( myMainObj, aMainShape ) )
117 bool isFound = false;
118 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
119 TopExp_Explorer anExp( aMainShape, aShapeType );
120 for ( ; anExp.More(); anExp.Next() )
121 if ( anExp.Current() == aShape )
129 // Verify number of sub-shapes
130 if ( mySubShapeType == TopAbs_SHAPE );
134 TopExp_Explorer anExp2( aShape, mySubShapeType );
135 TopTools_MapOfShape aMap;
136 for ( ; anExp2.More(); anExp2.Next() )
137 aMap.Add( anExp2.Current() );
139 return myNumber == aMap.Extent();
142 //=======================================================================
143 // name : SMESH_NumberFilter::getGeom
144 // Purpose : Retrieve geom object from SALOME_InteractiveObject
145 //=======================================================================
146 GEOM::GEOM_Object_ptr SMESH_NumberFilter::getGeom(
147 const Handle(SALOME_InteractiveObject)& theObj ) const
149 if ( theObj->isComponentType( "GEOM" ) )
151 Standard_Boolean aRes = Standard_False;
152 GEOM::GEOM_Object_var aGeomObj = GEOMBase::ConvertIOinGEOMObject( theObj, aRes );
153 return aRes ? aGeomObj._retn() : GEOM::GEOM_Object::_nil();
157 // Get geom object corresponding to the mesh
158 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
159 SALOMEDS::SObject_var aSO = aStudy->FindObjectID( theObj->getEntry() );
160 if ( aSO->_is_nil() )
161 return GEOM::GEOM_Object::_nil();
163 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( aSO );
164 for( ; anIter->More(); anIter->Next() )
166 SALOMEDS::SObject_var aSO = anIter->Value();
167 SALOMEDS::SObject_var aRefSO;
169 GEOM::GEOM_Object_var aMeshShape = GEOM::GEOM_Object::_narrow(
170 aSO->ReferencedObject( aRefSO )? aRefSO->GetObject() : aSO->GetObject() );
172 if ( !aMeshShape->_is_nil() )
173 return aMeshShape._retn();
176 return GEOM::GEOM_Object::_nil();
181 void SMESH_NumberFilter::SetSubShapeType( const TopAbs_ShapeEnum theSubShapeType )
183 mySubShapeType = theSubShapeType;
186 void SMESH_NumberFilter::SetNumber( const int theNumber )
188 myNumber = theNumber;
191 void SMESH_NumberFilter::SetClosedOnly( const bool theIsClosedOnly )
193 myIsClosedOnly = theIsClosedOnly;
196 void SMESH_NumberFilter::SetShapeType( const TopAbs_ShapeEnum theShapeType )
198 myShapeTypes.Add( theShapeType );
201 void SMESH_NumberFilter::SetMainShape( GEOM::GEOM_Object_ptr theMainObj )
203 myMainObj = GEOM::GEOM_Object::_duplicate( theMainObj );