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 <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
59 GEOM::GEOM_Object_var anObj;
61 const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_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()));
70 std::string aValue = aSO->GetIOR();
71 if (strcmp(aValue.c_str(), "") != 0) {
72 CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
73 CORBA::Object_var aCorbaObj = anORB->string_to_object(aValue.c_str());
74 anObj = GEOM::GEOM_Object::_narrow(aCorbaObj);
79 if (!CORBA::is_nil(anObj))
82 return GEOM::GEOM_Object::_nil();
85 //=======================================================================
86 // function : getShape
88 //=======================================================================
89 bool GEOM_SelectionFilter::getShape (const GEOM::GEOM_Object_ptr& theObject,
90 TopoDS_Shape& theShape) const
92 if ( !CORBA::is_nil( theObject ) )
94 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
95 ( SUIT_Session::session()->activeApplication() );
98 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( app->namingService() );
99 Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
100 GEOM::GEOM_Gen_var geomGen = GEOM::GEOM_Gen::_narrow( comp );
101 if ( !CORBA::is_nil( geomGen ) )
103 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( geomGen, theObject );
105 if ( !aTopoDSShape.IsNull() )
107 theShape = aTopoDSShape;
116 //=======================================================================
117 // function : contains
119 //=======================================================================
120 bool GEOM_SelectionFilter::contains( const int type ) const
122 return myTypes.contains( type );
125 //=======================================================================
128 //=======================================================================
129 void GEOM_SelectionFilter::add( const int type )
131 if ( !contains( type ) )
132 myTypes.append( type );
135 //=======================================================================
138 //=======================================================================
139 void GEOM_SelectionFilter::remove( const int type )
141 if ( contains( type ) )
142 myTypes.remove( type );
145 //=======================================================================
148 //=======================================================================
149 void GEOM_SelectionFilter::setAll( const bool all )
154 //=======================================================================
157 //=======================================================================
158 bool GEOM_SelectionFilter::isAll() const
163 //=======================================================================
164 // function : isShapeOk
166 //=======================================================================
167 bool GEOM_SelectionFilter::isShapeOk( const TopoDS_Shape& ) const