Salome HOME
26df6985eb75236fa651a17ec7cf6e3793eda6e7
[modules/geom.git] / src / GEOMFiltersSelection / GEOM_TypeFilter.cxx
1 //  GEOM GEOMGUI : Implementation of selection filters for GEOM module
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //              
24 //  File   : GEOM_TypeFilter.cxx
25 //  Author : Sergey LITONIN
26 //  Module : GEOM
27
28 #include "GEOM_TypeFilter.hxx"
29 #include "SALOME_InteractiveObject.hxx"
30 #include "GEOM_Client.hxx"
31 #include "QAD_Application.h"
32 #include "QAD_Desktop.h"
33 #include "utilities.h"
34
35 static GEOM::GEOM_Object_ptr convertIOinGEOMObject(
36   const Handle(SALOME_InteractiveObject)& theIO, Standard_Boolean& theResult )
37 {
38   theResult = Standard_False;
39   GEOM::GEOM_Object_var aReturnObject;
40   if ( !theIO.IsNull() )
41   {
42     const char* anEntry = theIO->getEntry();
43     SALOMEDS::SObject_var aSObj =
44       QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->FindObjectID( anEntry );
45     if ( !CORBA::is_nil( aSObj ) )
46     {
47       aReturnObject = GEOM::GEOM_Object::_narrow( aSObj->GetObject() );
48       theResult = !CORBA::is_nil( aReturnObject );
49     }
50   }
51   return aReturnObject._retn();
52 }
53
54 /*
55   Class       : GEOM_TypeFilter
56   Description : Filter for combaining several filters with logical operation (OR or AND)
57 */
58
59 IMPLEMENT_STANDARD_HANDLE( GEOM_TypeFilter, SALOME_TypeFilter )
60 IMPLEMENT_STANDARD_RTTIEXT( GEOM_TypeFilter, SALOME_TypeFilter )
61
62 //=======================================================================
63 // name    : GEOM_TypeFilter::GEOM_TypeFilter
64 // Purpose : Constructor
65 //=======================================================================
66 GEOM_TypeFilter::GEOM_TypeFilter( const int theType )
67 : SALOME_TypeFilter( "GEOM" )
68 {
69   myType = theType;
70 }
71
72 //=======================================================================
73 // name    : GEOM_TypeFilter::~GEOM_TypeFilter
74 // Purpose : Destructor
75 //=======================================================================
76 GEOM_TypeFilter::~GEOM_TypeFilter()
77 {
78 }
79
80 //=======================================================================
81 // name    : GEOM_TypeFilter::IsOk
82 // Purpose : Verify validity of entry object
83 //=======================================================================
84 Standard_Boolean GEOM_TypeFilter::IsOk( const Handle(SALOME_InteractiveObject)& theIO ) const
85 {
86   if ( SALOME_TypeFilter::IsOk( theIO ) )
87   {
88     Standard_Boolean aTestRes = Standard_False;
89     GEOM::GEOM_Object_var anObj = convertIOinGEOMObject( theIO, aTestRes );
90     if ( aTestRes && !anObj->_is_nil() )
91       return anObj->GetType() == myType;
92   }
93
94   return false;
95 }
96
97 //=======================================================================
98 // name    : GEOM_TypeFilter::SetType
99 // Purpose : Set type of object
100 //=======================================================================
101 void GEOM_TypeFilter::SetType( const int theType )
102 {
103   myType = theType;
104 }
105
106 //=======================================================================
107 // name    : GEOM_TypeFilter::GetType
108 // Purpose : Get type of object
109 //=======================================================================
110 int GEOM_TypeFilter::GetType() const
111 {
112   return myType;
113 }
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145