Salome HOME
6ca272b01908cf9e519c512f0ce23e14a2976c31
[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 "GEOM_Client.hxx"
32
33 #include "SALOME_InteractiveObject.hxx"
34 #include "GEOM_InteractiveObject.hxx"
35 #include "SALOME_TypeFilter.hxx"
36
37 #include "utilities.h"
38 #include "QAD_Application.h"
39 #include "QAD_Desktop.h"
40 #include "QAD_Study.h"
41
42 static GEOM_Client  ShapeReader;
43
44 GEOM_ShapeTypeFilter::GEOM_ShapeTypeFilter(TopAbs_ShapeEnum ShapeType,
45                                            GEOM::GEOM_Gen_ptr geom) 
46 {
47   myKind = ShapeType;
48   myComponentGeom = GEOM::GEOM_Gen::_narrow(geom);
49 }
50
51 Standard_Boolean GEOM_ShapeTypeFilter::IsOk(const Handle(SALOME_InteractiveObject)& anObj) const 
52 {
53   Handle(SALOME_TypeFilter) GeomFilter = new SALOME_TypeFilter( "GEOM" );
54   if ( !GeomFilter->IsOk(anObj) ) 
55     return false;
56   if ( anObj->hasEntry() ) {
57     QAD_Study*                     ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
58     SALOMEDS::Study_var            aStudy      = ActiveStudy->getStudyDocument();
59     SALOMEDS::SObject_var          obj         = aStudy->FindObjectID( anObj->getEntry() );
60     SALOMEDS::GenericAttribute_var anAttr;
61     SALOMEDS::AttributeIOR_var     anIOR;
62     if ( !obj->_is_nil() ) {
63        if (obj->FindAttribute(anAttr, "AttributeIOR")) {
64          anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
65          GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( anIOR->Value() );  
66          if ( aShape->_is_nil() )
67            return false;
68      
69          TopoDS_Shape    Shape = ShapeReader.GetShape( myComponentGeom, aShape );
70          if ( Shape.IsNull() )
71            return false;
72          
73          MESSAGE ( " myKind          = " << myKind );
74          MESSAGE ( " Shape.ShapeType = " << Shape.ShapeType() );
75          if ( myKind == TopAbs_SHAPE )
76            return true;
77          
78          if ( Shape.ShapeType() == myKind )
79            return true;
80          else
81            return false; 
82        }
83     }
84   }
85   
86   if ( anObj->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
87      Handle(GEOM_InteractiveObject) GObject =
88         Handle(GEOM_InteractiveObject)::DownCast(anObj);
89
90      GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( GObject->getIOR() );  
91      if ( aShape->_is_nil() )
92        return false;
93      
94      TopoDS_Shape    Shape = ShapeReader.GetShape( myComponentGeom, aShape );
95      if ( Shape.IsNull() )
96        return false;
97      
98      MESSAGE ( " myKind          = " << myKind );
99      MESSAGE ( " Shape.ShapeType = " << Shape.ShapeType() );
100      if ( myKind == TopAbs_SHAPE )
101        return true;
102      
103      if ( Shape.ShapeType() == myKind )
104        return true;
105      else
106        return false;  
107   } 
108   return false;
109 }