1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 #include "GEOM_SelectionFilter.h"
24 #include "GEOM_Client.hxx"
26 #include <LightApp_DataOwner.h>
27 #include <SalomeApp_Study.h>
28 #include <SalomeApp_Application.h>
30 #include <SALOME_LifeCycleCORBA.hxx>
32 #include <SUIT_Session.h>
34 //=======================================================================
35 // function : GEOM_SelectionFilter
37 //=======================================================================
38 GEOM_SelectionFilter::GEOM_SelectionFilter( SalomeApp_Study* study, const bool theAll )
39 : SalomeApp_Filter(study)
44 //=======================================================================
45 // function : ~GEOM_SelectionFilter
47 //=======================================================================
48 GEOM_SelectionFilter::~GEOM_SelectionFilter()
52 //=======================================================================
55 //=======================================================================
56 bool GEOM_SelectionFilter::isOk( const SUIT_DataOwner* sOwner ) const
58 GEOM::GEOM_Object_var obj = getObject( sOwner );
59 if ( !CORBA::is_nil( obj ) && obj->IsShape() )
65 if ( getShape( obj, shape ) )
66 return contains( shape.ShapeType() ) && isShapeOk( shape );
71 //=======================================================================
72 // function : getObject
74 //=======================================================================
75 GEOM::GEOM_Object_ptr GEOM_SelectionFilter::getObject( const SUIT_DataOwner* sOwner, const bool extractReference ) const
77 GEOM::GEOM_Object_var anObj;
79 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>(sOwner);
80 SalomeApp_Study* appStudy = getStudy();
81 if (owner && appStudy)
83 _PTR(Study) study = appStudy->studyDS();
84 QString entry = owner->entry();
86 _PTR(SObject) aSO (study->FindObjectID(entry.toStdString())), aRefSO;
87 if( extractReference && aSO && aSO->ReferencedObject( aRefSO ) )
91 std::string aValue = aSO->GetIOR();
92 if (strcmp(aValue.c_str(), "") != 0) {
93 CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
94 CORBA::Object_var aCorbaObj = anORB->string_to_object(aValue.c_str());
95 anObj = GEOM::GEOM_Object::_narrow(aCorbaObj);
100 if (!CORBA::is_nil(anObj))
101 return anObj._retn();
103 return GEOM::GEOM_Object::_nil();
106 //=======================================================================
107 // function : getShape
109 //=======================================================================
110 bool GEOM_SelectionFilter::getShape (const GEOM::GEOM_Object_ptr& theObject,
111 TopoDS_Shape& theShape) const
113 if ( !CORBA::is_nil( theObject ) )
115 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
116 ( SUIT_Session::session()->activeApplication() );
119 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( app->namingService() );
120 static GEOM::GEOM_Gen_var geomGen;
121 if(CORBA::is_nil( geomGen )) {
122 Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
123 geomGen = GEOM::GEOM_Gen::_narrow( comp );
125 if ( !CORBA::is_nil( geomGen ) )
127 TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( geomGen, theObject );
129 if ( !aTopoDSShape.IsNull() )
131 theShape = aTopoDSShape;
140 //=======================================================================
141 // function : contains
143 //=======================================================================
144 bool GEOM_SelectionFilter::contains( const int type ) const
146 return myTypes.contains( type );
149 //=======================================================================
152 //=======================================================================
153 void GEOM_SelectionFilter::add( const int type )
155 if ( !contains( type ) )
156 myTypes.append( type );
159 //=======================================================================
162 //=======================================================================
163 void GEOM_SelectionFilter::remove( const int type )
165 if ( contains( type ) )
166 myTypes.removeAll( type );
169 //=======================================================================
172 //=======================================================================
173 void GEOM_SelectionFilter::setAll( const bool all )
178 //=======================================================================
181 //=======================================================================
182 bool GEOM_SelectionFilter::isAll() const
187 //=======================================================================
188 // function : isShapeOk
190 //=======================================================================
191 bool GEOM_SelectionFilter::isShapeOk( const TopoDS_Shape& ) const