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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : GEOM_ShapeTypeFilter.cxx
25 // Author : Nicolas REJNERI
29 #include <Standard_Stream.hxx>
31 #include "GEOM_ShapeTypeFilter.ixx"
32 #include "SALOME_InteractiveObject.hxx"
33 #include "GEOM_Client.hxx"
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "utilities.h"
38 #include <TopoDS_Shape.hxx>
40 //=======================================================================
41 // function : getShape()
42 // purpose : returns a TopoDS_Shape stored in GEOM_Object
43 //=======================================================================
44 static bool getShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape )
46 if ( !CORBA::is_nil( theObject ) )
48 static GEOM::GEOM_Gen_var myGeom;
49 if(CORBA::is_nil(myGeom) {
50 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", "GEOM" );
51 myGeom = GEOM::GEOM_Gen::_narrow( comp );
53 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( myGeom, theObject );
55 if ( !aTopoDSShape.IsNull() )
57 theShape = aTopoDSShape;
64 //=======================================================================
65 // function : ConvertIOinGEOMObject()
67 //=======================================================================
68 static GEOM::GEOM_Object_ptr convertIOinGEOMObject(
69 const Handle(SALOME_InteractiveObject)& theIO, Standard_Boolean& theResult )
71 theResult = Standard_False;
72 GEOM::GEOM_Object_var aReturnObject;
73 if ( !theIO.IsNull() )
75 const char* anEntry = theIO->getEntry();
76 SALOMEDS::SObject_var aSObj =
77 QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->FindObjectID( anEntry );
78 if ( !CORBA::is_nil( aSObj ) )
80 aReturnObject = GEOM::GEOM_Object::_narrow( aSObj->GetObject() );
81 theResult = !CORBA::is_nil( aReturnObject );
84 return aReturnObject._retn();
87 //=======================================================================
88 // function : ShapeTypeFilter
90 //=======================================================================
91 GEOM_ShapeTypeFilter::GEOM_ShapeTypeFilter( const TopAbs_ShapeEnum theShapeType,
95 myShapeTypes.Add( theShapeType );
96 myTypeFilter = new SALOME_TypeFilter( "GEOM" );
99 //=======================================================================
100 // function : ShapeTypeFilter
102 //=======================================================================
103 GEOM_ShapeTypeFilter::GEOM_ShapeTypeFilter( const TColStd_MapOfInteger& theShapeTypes,
104 const bool theIsAll )
107 myShapeTypes = theShapeTypes;
108 myTypeFilter = new SALOME_TypeFilter( "GEOM" );
111 //=======================================================================
114 //=======================================================================
115 Standard_Boolean GEOM_ShapeTypeFilter::IsOk(
116 const Handle(SALOME_InteractiveObject)& anObj ) const
118 if ( !myTypeFilter->IsOk(anObj) )
119 return Standard_False;
121 Standard_Boolean aResult = Standard_False;
122 GEOM::GEOM_Object_ptr aGeomObj = convertIOinGEOMObject( anObj, aResult );
123 if ( !CORBA::is_nil( aGeomObj ) && aResult && aGeomObj->IsShape() )
128 if ( getShape( aGeomObj, aShape ) )
130 if ( myShapeTypes.Contains( aShape.ShapeType() ) )
131 return IsShapeOk( aShape );
134 return Standard_False;
137 //=======================================================================
138 // function : IsShapeOk
140 //=======================================================================
141 Standard_Boolean GEOM_ShapeTypeFilter::IsShapeOk( const TopoDS_Shape& ) const
143 return Standard_True;