]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMFiltersSelection/GEOM_SelectionFilter.cxx
Salome HOME
Using files from package LightApp instead of SalomeApp
[modules/geom.git] / src / GEOMFiltersSelection / GEOM_SelectionFilter.cxx
1 #include "GEOM_SelectionFilter.h"
2
3 #include "GEOM_Client.hxx"
4
5 #include <LightApp_DataOwner.h>
6 #include <SalomeApp_Study.h>
7 #include <SalomeApp_Application.h>
8
9 #include <SALOME_LifeCycleCORBA.hxx>
10
11 #include <SUIT_Session.h>
12
13 #include <SALOMEDSClient.hxx>
14
15
16 //=======================================================================
17 // function : GEOM_SelectionFilter
18 // purpose  :
19 //=======================================================================
20 GEOM_SelectionFilter::GEOM_SelectionFilter( SalomeApp_Study* study, const bool theAll )
21   : SalomeApp_Filter(study)
22 {
23   myAll = theAll;
24 }
25
26 //=======================================================================
27 // function : ~GEOM_SelectionFilter
28 // purpose  :
29 //=======================================================================
30 GEOM_SelectionFilter::~GEOM_SelectionFilter()
31 {
32 }
33
34 //=======================================================================
35 // function : isOk
36 // purpose  :
37 //=======================================================================
38 bool GEOM_SelectionFilter::isOk( const SUIT_DataOwner* sOwner ) const
39 {
40   GEOM::GEOM_Object_var obj = getObject( sOwner );
41   if ( !CORBA::is_nil( obj ) && obj->IsShape() )
42   {
43     if ( isAll() )
44       return true;
45
46     TopoDS_Shape shape;
47     if ( getShape( obj, shape ) )
48       return contains( shape.ShapeType() ) && isShapeOk( shape );
49   }
50   return false;
51 }
52
53 //=======================================================================
54 // function : getObject
55 // purpose  :
56 //=======================================================================
57 GEOM::GEOM_Object_ptr GEOM_SelectionFilter::getObject( const SUIT_DataOwner* sOwner, const bool extractReference ) const
58 {
59   GEOM::GEOM_Object_var anObj;
60
61   const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>(sOwner);
62   SalomeApp_Study* appStudy = getStudy();
63   if (owner && appStudy)
64   {
65     _PTR(Study) study = appStudy->studyDS();
66     QString entry = owner->entry();
67
68     _PTR(SObject) aSO (study->FindObjectID(entry.latin1())), aRefSO;
69     if( extractReference && aSO && aSO->ReferencedObject( aRefSO ) )
70       aSO = aRefSO;
71
72     if (aSO) {
73       std::string aValue = aSO->GetIOR();
74       if (strcmp(aValue.c_str(), "") != 0) {
75         CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
76         CORBA::Object_var aCorbaObj = anORB->string_to_object(aValue.c_str());
77         anObj = GEOM::GEOM_Object::_narrow(aCorbaObj);
78       }
79     }
80   }
81
82   if (!CORBA::is_nil(anObj))
83     return anObj._retn();
84
85   return GEOM::GEOM_Object::_nil();
86 }
87
88 //=======================================================================
89 // function : getShape
90 // purpose  :
91 //=======================================================================
92 bool GEOM_SelectionFilter::getShape (const GEOM::GEOM_Object_ptr& theObject,
93                                      TopoDS_Shape&                theShape) const
94 {
95   if ( !CORBA::is_nil( theObject ) )
96   {
97     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
98       ( SUIT_Session::session()->activeApplication() );
99     if ( app )
100     {
101       SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( app->namingService() );
102       Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
103       GEOM::GEOM_Gen_var geomGen = GEOM::GEOM_Gen::_narrow( comp );
104       if ( !CORBA::is_nil( geomGen ) )
105       {
106         TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( geomGen, theObject );
107
108         if ( !aTopoDSShape.IsNull() )
109         {
110           theShape = aTopoDSShape;
111           return true;
112         }
113       }
114     }
115   }
116   return false;
117 }
118
119 //=======================================================================
120 // function : contains
121 // purpose  :
122 //=======================================================================
123 bool GEOM_SelectionFilter::contains( const int type ) const
124 {
125   return myTypes.contains( type );
126 }
127
128 //=======================================================================
129 // function : add
130 // purpose  :
131 //=======================================================================
132 void GEOM_SelectionFilter::add( const int type )
133 {
134   if ( !contains( type ) )
135     myTypes.append( type );
136 }
137
138 //=======================================================================
139 // function : remove
140 // purpose  :
141 //=======================================================================
142 void GEOM_SelectionFilter::remove( const int type )
143 {
144   if ( contains( type ) )
145     myTypes.remove( type );
146 }
147
148 //=======================================================================
149 // function : setAll
150 // purpose  :
151 //=======================================================================
152 void GEOM_SelectionFilter::setAll( const bool all )
153 {
154   myAll = all;
155 }
156
157 //=======================================================================
158 // function : isAll
159 // purpose  :
160 //=======================================================================
161 bool GEOM_SelectionFilter::isAll() const
162 {
163   return myAll;
164 }
165
166 //=======================================================================
167 // function : isShapeOk
168 // purpose  :
169 //=======================================================================
170 bool GEOM_SelectionFilter::isShapeOk( const TopoDS_Shape& ) const
171 {
172   return true;
173 }