Salome HOME
Correct make file for shared modules script
[modules/geom.git] / src / GEOMFiltersSelection / GEOM_ShapeTypeFilter.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  GEOM GEOMFiltersSelection : filter selector for the viewer
23 //  File   : GEOM_ShapeTypeFilter.cxx
24 //  Author : Nicolas REJNERI
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include <Standard_Stream.hxx>
29
30 #include "GEOM_ShapeTypeFilter.ixx"
31 #include "SALOME_InteractiveObject.hxx"
32 #include "GEOM_Client.hxx"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
36
37 #include <TopoDS_Shape.hxx>
38
39 //=======================================================================
40 // function : getShape()
41 // purpose  : returns a TopoDS_Shape stored in GEOM_Object
42 //=======================================================================
43 static bool getShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape )
44 {
45   if ( !CORBA::is_nil( theObject ) )
46   {
47     static GEOM::GEOM_Gen_var myGeom;
48     if(CORBA::is_nil(myGeom) {
49       Engines::Component_var comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", "GEOM" );
50       myGeom = GEOM::GEOM_Gen::_narrow( comp );
51     }
52     TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( myGeom, theObject );
53         
54     if ( !aTopoDSShape.IsNull() )
55     {
56       theShape = aTopoDSShape;
57        return true;
58     }
59   }
60   return false;
61 }
62
63 //=======================================================================
64 // function : ConvertIOinGEOMObject()
65 // purpose  :
66 //=======================================================================
67 static GEOM::GEOM_Object_ptr convertIOinGEOMObject(
68   const Handle(SALOME_InteractiveObject)& theIO, Standard_Boolean& theResult )
69 {
70   theResult = Standard_False;
71   GEOM::GEOM_Object_var aReturnObject;
72   if ( !theIO.IsNull() )
73   {
74     const char* anEntry = theIO->getEntry();
75     SALOMEDS::SObject_var aSObj =
76       QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->FindObjectID( anEntry );
77     if ( !CORBA::is_nil( aSObj ) )
78     {
79       aReturnObject = GEOM::GEOM_Object::_narrow( aSObj->GetObject() );
80       theResult = !CORBA::is_nil( aReturnObject );
81     }
82   }
83   return aReturnObject._retn();
84 }
85
86 //=======================================================================
87 // function : ShapeTypeFilter
88 // purpose  : 
89 //=======================================================================
90 GEOM_ShapeTypeFilter::GEOM_ShapeTypeFilter( const TopAbs_ShapeEnum theShapeType,
91                                             const bool theIsAll ) 
92 {
93   myIsAll = theIsAll;
94   myShapeTypes.Add( theShapeType );
95   myTypeFilter = new SALOME_TypeFilter( "GEOM" );
96 }
97
98 //=======================================================================
99 // function : ShapeTypeFilter
100 // purpose  : 
101 //=======================================================================
102 GEOM_ShapeTypeFilter::GEOM_ShapeTypeFilter( const TColStd_MapOfInteger& theShapeTypes,
103                                             const bool theIsAll ) 
104 {
105   myIsAll = theIsAll;
106   myShapeTypes = theShapeTypes;
107   myTypeFilter = new SALOME_TypeFilter( "GEOM" );
108 }
109
110 //=======================================================================
111 // function : IsOk
112 // purpose  : 
113 //=======================================================================
114 Standard_Boolean GEOM_ShapeTypeFilter::IsOk(
115   const Handle(SALOME_InteractiveObject)& anObj ) const 
116 {
117   if ( !myTypeFilter->IsOk(anObj) ) 
118     return Standard_False;
119
120   Standard_Boolean aResult = Standard_False;
121   GEOM::GEOM_Object_ptr aGeomObj = convertIOinGEOMObject( anObj, aResult );
122   if ( !CORBA::is_nil( aGeomObj ) && aResult && aGeomObj->IsShape() )
123   {
124     if ( myIsAll )
125       return true;
126     TopoDS_Shape aShape;
127     if ( getShape( aGeomObj, aShape ) )
128     {
129       if ( myShapeTypes.Contains( aShape.ShapeType() ) )
130         return IsShapeOk( aShape );
131     }
132   }
133   return Standard_False;
134 }
135
136 //=======================================================================
137 // function : IsShapeOk
138 // purpose  : 
139 //=======================================================================
140 Standard_Boolean GEOM_ShapeTypeFilter::IsShapeOk( const TopoDS_Shape& ) const
141 {
142   return Standard_True;
143 }
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167