1 #include "GEOM_SelectionFilter.h"
3 #include "GEOM_Client.hxx"
5 #include <SalomeApp_DataOwner.h>
6 #include <SalomeApp_Study.h>
7 #include <SalomeApp_Application.h>
9 #include <SALOME_LifeCycleCORBA.hxx>
11 #include <SUIT_Session.h>
13 #include <SALOMEDS_SObject.hxx>
17 //=======================================================================
18 // function : GEOM_SelectionFilter
20 //=======================================================================
21 GEOM_SelectionFilter::GEOM_SelectionFilter( SalomeApp_Study* study, const bool theAll )
22 : SalomeApp_Filter(study)
27 //=======================================================================
28 // function : ~GEOM_SelectionFilter
30 //=======================================================================
31 GEOM_SelectionFilter::~GEOM_SelectionFilter()
35 //=======================================================================
38 //=======================================================================
39 bool GEOM_SelectionFilter::isOk( const SUIT_DataOwner* sOwner ) const
41 GEOM::GEOM_Object_var obj = getObject( sOwner );
42 if ( !CORBA::is_nil( obj ) && obj->IsShape() )
48 if ( getShape( obj, shape ) )
49 return contains( shape.ShapeType() ) && isShapeOk( shape );
54 //=======================================================================
55 // function : getObject
57 //=======================================================================
58 GEOM::GEOM_Object_ptr GEOM_SelectionFilter::getObject( const SUIT_DataOwner* sOwner ) const
60 GEOM::GEOM_Object_var anObj;
62 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*> ( sOwner );
63 SalomeApp_Study* appStudy = getStudy();
64 if ( owner && appStudy )
66 _PTR(Study) study = appStudy->studyDS();
67 QString entry = owner->entry();
69 _PTR(SObject) aSO( study->FindObjectID( entry.latin1() ) );
71 anObj = GEOM::GEOM_Object::_narrow(dynamic_cast<SALOMEDS_SObject*>(aSO.get())->GetObject());
74 if ( !CORBA::is_nil( anObj ) )
77 return GEOM::GEOM_Object::_nil();
80 //=======================================================================
81 // function : getShape
83 //=======================================================================
84 bool GEOM_SelectionFilter::getShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape ) const
86 if ( !CORBA::is_nil( theObject ) )
88 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
91 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( app->namingService() );
92 Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
93 GEOM::GEOM_Gen_var geomGen = GEOM::GEOM_Gen::_narrow( comp );
94 if ( !CORBA::is_nil( geomGen ) )
96 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( geomGen, theObject );
98 if ( !aTopoDSShape.IsNull() )
100 theShape = aTopoDSShape;
109 //=======================================================================
110 // function : contains
112 //=======================================================================
113 bool GEOM_SelectionFilter::contains( const int type ) const
115 return myTypes.contains( type );
118 //=======================================================================
121 //=======================================================================
122 void GEOM_SelectionFilter::add( const int type )
124 if ( !contains( type ) )
125 myTypes.append( type );
128 //=======================================================================
131 //=======================================================================
132 void GEOM_SelectionFilter::remove( const int type )
134 if ( contains( type ) )
135 myTypes.remove( type );
138 //=======================================================================
141 //=======================================================================
142 void GEOM_SelectionFilter::setAll( const bool all )
147 //=======================================================================
150 //=======================================================================
151 bool GEOM_SelectionFilter::isAll() const
156 //=======================================================================
157 // function : isShapeOk
159 //=======================================================================
160 bool GEOM_SelectionFilter::isShapeOk( const TopoDS_Shape& ) const