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/
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 #include <SALOMEDSClient.hxx>
35 //=======================================================================
36 // function : GEOM_SelectionFilter
38 //=======================================================================
39 GEOM_SelectionFilter::GEOM_SelectionFilter( SalomeApp_Study* study, const bool theAll )
40 : SalomeApp_Filter(study)
45 //=======================================================================
46 // function : ~GEOM_SelectionFilter
48 //=======================================================================
49 GEOM_SelectionFilter::~GEOM_SelectionFilter()
53 //=======================================================================
56 //=======================================================================
57 bool GEOM_SelectionFilter::isOk( const SUIT_DataOwner* sOwner ) const
59 GEOM::GEOM_Object_var obj = getObject( sOwner );
60 if ( !CORBA::is_nil( obj ) && obj->IsShape() )
66 if ( getShape( obj, shape ) )
67 return contains( shape.ShapeType() ) && isShapeOk( shape );
72 //=======================================================================
73 // function : getObject
75 //=======================================================================
76 GEOM::GEOM_Object_ptr GEOM_SelectionFilter::getObject( const SUIT_DataOwner* sOwner, const bool extractReference ) const
78 GEOM::GEOM_Object_var anObj;
80 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>(sOwner);
81 SalomeApp_Study* appStudy = getStudy();
82 if (owner && appStudy)
84 _PTR(Study) study = appStudy->studyDS();
85 QString entry = owner->entry();
87 _PTR(SObject) aSO (study->FindObjectID(entry.latin1())), aRefSO;
88 if( extractReference && aSO && aSO->ReferencedObject( aRefSO ) )
92 std::string aValue = aSO->GetIOR();
93 if (strcmp(aValue.c_str(), "") != 0) {
94 CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
95 CORBA::Object_var aCorbaObj = anORB->string_to_object(aValue.c_str());
96 anObj = GEOM::GEOM_Object::_narrow(aCorbaObj);
101 if (!CORBA::is_nil(anObj))
102 return anObj._retn();
104 return GEOM::GEOM_Object::_nil();
107 //=======================================================================
108 // function : getShape
110 //=======================================================================
111 bool GEOM_SelectionFilter::getShape (const GEOM::GEOM_Object_ptr& theObject,
112 TopoDS_Shape& theShape) const
114 if ( !CORBA::is_nil( theObject ) )
116 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
117 ( SUIT_Session::session()->activeApplication() );
120 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( app->namingService() );
121 Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
122 GEOM::GEOM_Gen_var 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.remove( 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