1 #include "GEOM_SelectionFilter.h"
3 #include "GEOM_Client.hxx"
5 #include <LightApp_DataOwner.h>
6 #include <SalomeApp_Study.h>
7 #include <SalomeApp_Application.h>
9 #include <SALOME_LifeCycleCORBA.hxx>
11 #include <SUIT_Session.h>
13 #include <SALOMEDSClient.hxx>
16 //=======================================================================
17 // function : GEOM_SelectionFilter
19 //=======================================================================
20 GEOM_SelectionFilter::GEOM_SelectionFilter( SalomeApp_Study* study, const bool theAll )
21 : SalomeApp_Filter(study)
26 //=======================================================================
27 // function : ~GEOM_SelectionFilter
29 //=======================================================================
30 GEOM_SelectionFilter::~GEOM_SelectionFilter()
34 //=======================================================================
37 //=======================================================================
38 bool GEOM_SelectionFilter::isOk( const SUIT_DataOwner* sOwner ) const
40 GEOM::GEOM_Object_var obj = getObject( sOwner );
41 if ( !CORBA::is_nil( obj ) && obj->IsShape() )
47 if ( getShape( obj, shape ) )
48 return contains( shape.ShapeType() ) && isShapeOk( shape );
53 //=======================================================================
54 // function : getObject
56 //=======================================================================
57 GEOM::GEOM_Object_ptr GEOM_SelectionFilter::getObject( const SUIT_DataOwner* sOwner, const bool extractReference ) const
59 GEOM::GEOM_Object_var anObj;
61 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>(sOwner);
62 SalomeApp_Study* appStudy = getStudy();
63 if (owner && appStudy)
65 _PTR(Study) study = appStudy->studyDS();
66 QString entry = owner->entry();
68 _PTR(SObject) aSO (study->FindObjectID(entry.latin1())), aRefSO;
69 if( extractReference && aSO && aSO->ReferencedObject( aRefSO ) )
73 std::string aValue = aSO->GetIOR();
74 if (strcmp(aValue.c_str(), "") != 0) {
75 CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
76 CORBA::Object_var aCorbaObj = anORB->string_to_object(aValue.c_str());
77 anObj = GEOM::GEOM_Object::_narrow(aCorbaObj);
82 if (!CORBA::is_nil(anObj))
85 return GEOM::GEOM_Object::_nil();
88 //=======================================================================
89 // function : getShape
91 //=======================================================================
92 bool GEOM_SelectionFilter::getShape (const GEOM::GEOM_Object_ptr& theObject,
93 TopoDS_Shape& theShape) const
95 if ( !CORBA::is_nil( theObject ) )
97 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
98 ( SUIT_Session::session()->activeApplication() );
101 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( app->namingService() );
102 Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
103 GEOM::GEOM_Gen_var geomGen = GEOM::GEOM_Gen::_narrow( comp );
104 if ( !CORBA::is_nil( geomGen ) )
106 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( geomGen, theObject );
108 if ( !aTopoDSShape.IsNull() )
110 theShape = aTopoDSShape;
119 //=======================================================================
120 // function : contains
122 //=======================================================================
123 bool GEOM_SelectionFilter::contains( const int type ) const
125 return myTypes.contains( type );
128 //=======================================================================
131 //=======================================================================
132 void GEOM_SelectionFilter::add( const int type )
134 if ( !contains( type ) )
135 myTypes.append( type );
138 //=======================================================================
141 //=======================================================================
142 void GEOM_SelectionFilter::remove( const int type )
144 if ( contains( type ) )
145 myTypes.remove( type );
148 //=======================================================================
151 //=======================================================================
152 void GEOM_SelectionFilter::setAll( const bool all )
157 //=======================================================================
160 //=======================================================================
161 bool GEOM_SelectionFilter::isAll() const
166 //=======================================================================
167 // function : isShapeOk
169 //=======================================================================
170 bool GEOM_SelectionFilter::isShapeOk( const TopoDS_Shape& ) const