1 // GEOM GEOMFiltersSelection : filter selector for the viewer
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 : GEOM_ShapeTypeFilter.cxx
25 // Author : Nicolas REJNERI
30 #include "GEOM_ShapeTypeFilter.ixx"
31 #include "SALOME_InteractiveObject.hxx"
32 #include "GEOM_Client.hxx"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
37 #include <TopoDS_Shape.hxx>
39 //=======================================================================
40 // function : getShape()
41 // purpose : returns a TopoDS_Shape stored in GEOM_Object
42 //=======================================================================
43 static bool getShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape )
45 if ( !CORBA::is_nil( theObject ) )
47 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", "GEOM" );
48 GEOM::GEOM_Gen_var myGeom = GEOM::GEOM_Gen::_narrow( comp );
49 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( myGeom, theObject );
51 if ( !aTopoDSShape.IsNull() )
53 theShape = aTopoDSShape;
60 //=======================================================================
61 // function : ConvertIOinGEOMObject()
63 //=======================================================================
64 static GEOM::GEOM_Object_ptr convertIOinGEOMObject(
65 const Handle(SALOME_InteractiveObject)& theIO, Standard_Boolean& theResult )
67 theResult = Standard_False;
68 GEOM::GEOM_Object_var aReturnObject;
69 if ( !theIO.IsNull() )
71 const char* anEntry = theIO->getEntry();
72 SALOMEDS::SObject_var aSObj =
73 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->FindObjectID( anEntry );
74 if ( !CORBA::is_nil( aSObj ) )
76 aReturnObject = GEOM::GEOM_Object::_narrow( aSObj->GetObject() );
77 theResult = !CORBA::is_nil( aReturnObject );
80 return aReturnObject._retn();
83 //=======================================================================
84 // function : ShapeTypeFilter
86 //=======================================================================
87 GEOM_ShapeTypeFilter::GEOM_ShapeTypeFilter( const TopAbs_ShapeEnum theShapeType,
91 myShapeTypes.Add( theShapeType );
92 myTypeFilter = new SALOME_TypeFilter( "GEOM" );
95 //=======================================================================
96 // function : ShapeTypeFilter
98 //=======================================================================
99 GEOM_ShapeTypeFilter::GEOM_ShapeTypeFilter( const TColStd_MapOfInteger& theShapeTypes,
100 const bool theIsAll )
103 myShapeTypes = theShapeTypes;
104 myTypeFilter = new SALOME_TypeFilter( "GEOM" );
107 //=======================================================================
110 //=======================================================================
111 Standard_Boolean GEOM_ShapeTypeFilter::IsOk(
112 const Handle(SALOME_InteractiveObject)& anObj ) const
114 if ( !myTypeFilter->IsOk(anObj) )
115 return Standard_False;
117 Standard_Boolean aResult = Standard_False;
118 GEOM::GEOM_Object_ptr aGeomObj = convertIOinGEOMObject( anObj, aResult );
119 if ( !CORBA::is_nil( aGeomObj ) && aResult && aGeomObj->IsShape() )
124 if ( getShape( aGeomObj, aShape ) )
126 if ( myShapeTypes.Contains( aShape.ShapeType() ) )
127 return IsShapeOk( aShape );
130 return Standard_False;
133 //=======================================================================
134 // function : IsShapeOk
136 //=======================================================================
137 Standard_Boolean GEOM_ShapeTypeFilter::IsShapeOk( const TopoDS_Shape& ) const
139 return Standard_True;