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