Salome HOME
Fix for PAL8309(now, if the ctrl key is pressed, the input coordinates function(by...
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : GEOM_ShapeTypeFilter.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
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     Engines::Component_var comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", "GEOM" );
48     GEOM::GEOM_Gen_var myGeom   = GEOM::GEOM_Gen::_narrow( comp );
49     TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( myGeom, theObject );
50         
51     if ( !aTopoDSShape.IsNull() )
52     {
53       theShape = aTopoDSShape;
54        return true;
55     }
56   }
57   return false;
58 }
59
60 //=======================================================================
61 // function : ConvertIOinGEOMObject()
62 // purpose  :
63 //=======================================================================
64 static GEOM::GEOM_Object_ptr convertIOinGEOMObject(
65   const Handle(SALOME_InteractiveObject)& theIO, Standard_Boolean& theResult )
66 {
67   theResult = Standard_False;
68   GEOM::GEOM_Object_var aReturnObject;
69   if ( !theIO.IsNull() )
70   {
71     const char* anEntry = theIO->getEntry();
72     SALOMEDS::SObject_var aSObj =
73       QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->FindObjectID( anEntry );
74     if ( !CORBA::is_nil( aSObj ) )
75     {
76       aReturnObject = GEOM::GEOM_Object::_narrow( aSObj->GetObject() );
77       theResult = !CORBA::is_nil( aReturnObject );
78     }
79   }
80   return aReturnObject._retn();
81 }
82
83 //=======================================================================
84 // function : ShapeTypeFilter
85 // purpose  : 
86 //=======================================================================
87 GEOM_ShapeTypeFilter::GEOM_ShapeTypeFilter( const TopAbs_ShapeEnum theShapeType,
88                                             const bool theIsAll ) 
89 {
90   myIsAll = theIsAll;
91   myShapeTypes.Add( theShapeType );
92   myTypeFilter = new SALOME_TypeFilter( "GEOM" );
93 }
94
95 //=======================================================================
96 // function : ShapeTypeFilter
97 // purpose  : 
98 //=======================================================================
99 GEOM_ShapeTypeFilter::GEOM_ShapeTypeFilter( const TColStd_MapOfInteger& theShapeTypes,
100                                             const bool theIsAll ) 
101 {
102   myIsAll = theIsAll;
103   myShapeTypes = theShapeTypes;
104   myTypeFilter = new SALOME_TypeFilter( "GEOM" );
105 }
106
107 //=======================================================================
108 // function : IsOk
109 // purpose  : 
110 //=======================================================================
111 Standard_Boolean GEOM_ShapeTypeFilter::IsOk(
112   const Handle(SALOME_InteractiveObject)& anObj ) const 
113 {
114   if ( !myTypeFilter->IsOk(anObj) ) 
115     return Standard_False;
116
117   Standard_Boolean aResult = Standard_False;
118   GEOM::GEOM_Object_ptr aGeomObj = convertIOinGEOMObject( anObj, aResult );
119   if ( !CORBA::is_nil( aGeomObj ) && aResult && aGeomObj->IsShape() )
120   {
121     if ( myIsAll )
122       return true;
123     TopoDS_Shape aShape;
124     if ( getShape( aGeomObj, aShape ) )
125     {
126       if ( myShapeTypes.Contains( aShape.ShapeType() ) )
127         return IsShapeOk( aShape );
128     }
129   }
130   return Standard_False;
131 }
132
133 //=======================================================================
134 // function : IsShapeOk
135 // purpose  : 
136 //=======================================================================
137 Standard_Boolean GEOM_ShapeTypeFilter::IsShapeOk( const TopoDS_Shape& ) const
138 {
139   return Standard_True;
140 }
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164