1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GEOM_SelectionFilter.h"
22 #include "GEOM_Client.hxx"
24 #include <LightApp_DataOwner.h>
25 #include <SalomeApp_Study.h>
26 #include <SalomeApp_Application.h>
28 #include <SALOME_LifeCycleCORBA.hxx>
30 #include <SUIT_Session.h>
32 //=======================================================================
33 // function : GEOM_SelectionFilter
35 //=======================================================================
36 GEOM_SelectionFilter::GEOM_SelectionFilter( SalomeApp_Study* study, const bool theAll )
37 : SalomeApp_Filter(study)
42 //=======================================================================
43 // function : ~GEOM_SelectionFilter
45 //=======================================================================
46 GEOM_SelectionFilter::~GEOM_SelectionFilter()
50 //=======================================================================
53 //=======================================================================
54 bool GEOM_SelectionFilter::isOk( const SUIT_DataOwner* sOwner ) const
56 GEOM::GEOM_Object_var obj = getObject( sOwner );
57 if ( !CORBA::is_nil( obj ) && obj->IsShape() )
63 if ( getShape( obj, shape ) )
64 return contains( shape.ShapeType() ) && isShapeOk( shape );
69 //=======================================================================
70 // function : getObject
72 //=======================================================================
73 GEOM::GEOM_Object_ptr GEOM_SelectionFilter::getObject( const SUIT_DataOwner* sOwner, const bool extractReference ) const
75 GEOM::GEOM_Object_var anObj;
77 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>(sOwner);
78 SalomeApp_Study* appStudy = getStudy();
79 if (owner && appStudy)
81 _PTR(Study) study = appStudy->studyDS();
82 QString entry = owner->entry();
84 _PTR(SObject) aSO (study->FindObjectID(entry.toStdString())), aRefSO;
85 if( extractReference && aSO && aSO->ReferencedObject( aRefSO ) )
89 std::string aValue = aSO->GetIOR();
90 if (strcmp(aValue.c_str(), "") != 0) {
91 CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
92 CORBA::Object_var aCorbaObj = anORB->string_to_object(aValue.c_str());
93 anObj = GEOM::GEOM_Object::_narrow(aCorbaObj);
98 if (!CORBA::is_nil(anObj))
101 return GEOM::GEOM_Object::_nil();
104 //=======================================================================
105 // function : getShape
107 //=======================================================================
108 bool GEOM_SelectionFilter::getShape (const GEOM::GEOM_Object_ptr& theObject,
109 TopoDS_Shape& theShape) const
111 if ( !CORBA::is_nil( theObject ) )
113 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
114 ( SUIT_Session::session()->activeApplication() );
117 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( app->namingService() );
118 static GEOM::GEOM_Gen_var geomGen;
119 if(CORBA::is_nil( geomGen )) {
120 Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
121 geomGen = GEOM::GEOM_Gen::_narrow( comp );
123 if ( !CORBA::is_nil( geomGen ) )
125 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( geomGen, theObject );
127 if ( !aTopoDSShape.IsNull() )
129 theShape = aTopoDSShape;
138 //=======================================================================
139 // function : contains
141 //=======================================================================
142 bool GEOM_SelectionFilter::contains( const int type ) const
144 return myTypes.contains( type );
147 //=======================================================================
150 //=======================================================================
151 void GEOM_SelectionFilter::add( const int type )
153 if ( !contains( type ) )
154 myTypes.append( type );
157 //=======================================================================
160 //=======================================================================
161 void GEOM_SelectionFilter::remove( const int type )
163 if ( contains( type ) )
164 myTypes.removeAll( type );
167 //=======================================================================
170 //=======================================================================
171 void GEOM_SelectionFilter::setAll( const bool all )
176 //=======================================================================
179 //=======================================================================
180 bool GEOM_SelectionFilter::isAll() const
185 //=======================================================================
186 // function : isShapeOk
188 //=======================================================================
189 bool GEOM_SelectionFilter::isShapeOk( const TopoDS_Shape& ) const