1 // Copyright (C) 2007-2023 CEA, EDF, 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, or (at your option) any later version.
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
23 #include "GEOM_SelectionFilter.h"
25 #include "GEOM_Client.hxx"
27 #include <LightApp_DataOwner.h>
28 #include <SalomeApp_Study.h>
29 #include <SalomeApp_Application.h>
31 #include <SALOME_LifeCycleCORBA.hxx>
33 #include <SUIT_Session.h>
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 );
70 // IMP 0020435: fine local selection
72 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>(sOwner);
74 QString entry = owner->entry();
75 int index = entry.lastIndexOf("_");
85 //=======================================================================
86 // function : getObject
88 //=======================================================================
89 GEOM::GEOM_Object_ptr GEOM_SelectionFilter::getObject (const SUIT_DataOwner* sOwner,
90 const bool extractReference) const
92 GEOM::GEOM_Object_var anObj;
94 const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>(sOwner);
95 SalomeApp_Study* appStudy = getStudy();
96 if (owner && appStudy)
98 _PTR(Study) study = appStudy->studyDS();
99 QString entry = owner->entry();
101 _PTR(SObject) aSO (study->FindObjectID(entry.toStdString())), aRefSO;
102 if( extractReference && aSO && aSO->ReferencedObject( aRefSO ) )
106 std::string aValue = aSO->GetIOR();
107 if (strcmp(aValue.c_str(), "") != 0) {
108 CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
109 CORBA::Object_var aCorbaObj = anORB->string_to_object(aValue.c_str());
110 anObj = GEOM::GEOM_Object::_narrow(aCorbaObj);
115 if (!CORBA::is_nil(anObj))
116 return anObj._retn();
118 return GEOM::GEOM_Object::_nil();
121 //=======================================================================
122 // function : getShape
124 //=======================================================================
125 bool GEOM_SelectionFilter::getShape (const GEOM::GEOM_Object_ptr& theObject,
126 TopoDS_Shape& theShape) const
128 if ( !CORBA::is_nil( theObject ) )
130 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
131 ( SUIT_Session::session()->activeApplication() );
134 SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( app->namingService() );
135 static GEOM::GEOM_Gen_var geomGen;
136 if(CORBA::is_nil( geomGen )) {
137 Engines::EngineComponent_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
138 geomGen = GEOM::GEOM_Gen::_narrow( comp );
140 if ( !CORBA::is_nil( geomGen ) )
142 TopoDS_Shape aTopoDSShape = GEOM_Client::get_client().GetShape( geomGen, theObject );
144 if ( !aTopoDSShape.IsNull() )
146 theShape = aTopoDSShape;
155 //=======================================================================
156 // function : contains
158 //=======================================================================
159 bool GEOM_SelectionFilter::contains( const int type ) const
161 return myTypes.contains( type );
164 //=======================================================================
167 //=======================================================================
168 void GEOM_SelectionFilter::add( const int type )
170 if ( !contains( type ) )
171 myTypes.append( type );
174 //=======================================================================
177 //=======================================================================
178 void GEOM_SelectionFilter::remove( const int type )
180 if ( contains( type ) )
181 myTypes.removeAll( type );
184 //=======================================================================
187 //=======================================================================
188 void GEOM_SelectionFilter::setAll( const bool all )
193 //=======================================================================
196 //=======================================================================
197 bool GEOM_SelectionFilter::isAll() const
202 //=======================================================================
203 // function : isShapeOk
205 //=======================================================================
206 bool GEOM_SelectionFilter::isShapeOk( const TopoDS_Shape& ) const