X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOMFiltersSelection%2FGEOM_ShapeTypeFilter.cxx;h=1de7bd2e01f7a16cddb7574fa8f07cb366121e64;hb=ffe7a66382675c09eb24ef8345361cf5b1133033;hp=6ca272b01908cf9e519c512f0ce23e14a2976c31;hpb=0f1369c27fd6a84ba1149c3c5f3ed181acc055f1;p=modules%2Fgeom.git diff --git a/src/GEOMFiltersSelection/GEOM_ShapeTypeFilter.cxx b/src/GEOMFiltersSelection/GEOM_ShapeTypeFilter.cxx index 6ca272b01..1de7bd2e0 100644 --- a/src/GEOMFiltersSelection/GEOM_ShapeTypeFilter.cxx +++ b/src/GEOMFiltersSelection/GEOM_ShapeTypeFilter.cxx @@ -17,7 +17,7 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // // @@ -26,84 +26,143 @@ // Module : GEOM // $Header$ -using namespace std; -#include "GEOM_ShapeTypeFilter.ixx" -#include "GEOM_Client.hxx" +#include +#include "GEOM_ShapeTypeFilter.ixx" #include "SALOME_InteractiveObject.hxx" -#include "GEOM_InteractiveObject.hxx" -#include "SALOME_TypeFilter.hxx" - -#include "utilities.h" +#include "GEOM_Client.hxx" #include "QAD_Application.h" #include "QAD_Desktop.h" -#include "QAD_Study.h" +#include "utilities.h" -static GEOM_Client ShapeReader; +#include -GEOM_ShapeTypeFilter::GEOM_ShapeTypeFilter(TopAbs_ShapeEnum ShapeType, - GEOM::GEOM_Gen_ptr geom) +//======================================================================= +// function : getShape() +// purpose : returns a TopoDS_Shape stored in GEOM_Object +//======================================================================= +static bool getShape( const GEOM::GEOM_Object_ptr& theObject, TopoDS_Shape& theShape ) { - myKind = ShapeType; - myComponentGeom = GEOM::GEOM_Gen::_narrow(geom); + if ( !CORBA::is_nil( theObject ) ) + { + static GEOM::GEOM_Gen_var myGeom; + if(CORBA::is_nil(myGeom) { + Engines::Component_var comp = QAD_Application::getDesktop()->getEngine( "FactoryServer", "GEOM" ); + myGeom = GEOM::GEOM_Gen::_narrow( comp ); + } + TopoDS_Shape aTopoDSShape = GEOM_Client().GetShape( myGeom, theObject ); + + if ( !aTopoDSShape.IsNull() ) + { + theShape = aTopoDSShape; + return true; + } + } + return false; } -Standard_Boolean GEOM_ShapeTypeFilter::IsOk(const Handle(SALOME_InteractiveObject)& anObj) const +//======================================================================= +// function : ConvertIOinGEOMObject() +// purpose : +//======================================================================= +static GEOM::GEOM_Object_ptr convertIOinGEOMObject( + const Handle(SALOME_InteractiveObject)& theIO, Standard_Boolean& theResult ) { - Handle(SALOME_TypeFilter) GeomFilter = new SALOME_TypeFilter( "GEOM" ); - if ( !GeomFilter->IsOk(anObj) ) - return false; - if ( anObj->hasEntry() ) { - QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy(); - SALOMEDS::Study_var aStudy = ActiveStudy->getStudyDocument(); - SALOMEDS::SObject_var obj = aStudy->FindObjectID( anObj->getEntry() ); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if ( !obj->_is_nil() ) { - if (obj->FindAttribute(anAttr, "AttributeIOR")) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( anIOR->Value() ); - if ( aShape->_is_nil() ) - return false; - - TopoDS_Shape Shape = ShapeReader.GetShape( myComponentGeom, aShape ); - if ( Shape.IsNull() ) - return false; - - MESSAGE ( " myKind = " << myKind ); - MESSAGE ( " Shape.ShapeType = " << Shape.ShapeType() ); - if ( myKind == TopAbs_SHAPE ) - return true; - - if ( Shape.ShapeType() == myKind ) - return true; - else - return false; - } + theResult = Standard_False; + GEOM::GEOM_Object_var aReturnObject; + if ( !theIO.IsNull() ) + { + const char* anEntry = theIO->getEntry(); + SALOMEDS::SObject_var aSObj = + QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->FindObjectID( anEntry ); + if ( !CORBA::is_nil( aSObj ) ) + { + aReturnObject = GEOM::GEOM_Object::_narrow( aSObj->GetObject() ); + theResult = !CORBA::is_nil( aReturnObject ); } } - - if ( anObj->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) { - Handle(GEOM_InteractiveObject) GObject = - Handle(GEOM_InteractiveObject)::DownCast(anObj); - - GEOM::GEOM_Shape_var aShape = myComponentGeom->GetIORFromString( GObject->getIOR() ); - if ( aShape->_is_nil() ) - return false; - - TopoDS_Shape Shape = ShapeReader.GetShape( myComponentGeom, aShape ); - if ( Shape.IsNull() ) - return false; - - MESSAGE ( " myKind = " << myKind ); - MESSAGE ( " Shape.ShapeType = " << Shape.ShapeType() ); - if ( myKind == TopAbs_SHAPE ) - return true; - - if ( Shape.ShapeType() == myKind ) - return true; - else - return false; - } - return false; + return aReturnObject._retn(); +} + +//======================================================================= +// function : ShapeTypeFilter +// purpose : +//======================================================================= +GEOM_ShapeTypeFilter::GEOM_ShapeTypeFilter( const TopAbs_ShapeEnum theShapeType, + const bool theIsAll ) +{ + myIsAll = theIsAll; + myShapeTypes.Add( theShapeType ); + myTypeFilter = new SALOME_TypeFilter( "GEOM" ); +} + +//======================================================================= +// function : ShapeTypeFilter +// purpose : +//======================================================================= +GEOM_ShapeTypeFilter::GEOM_ShapeTypeFilter( const TColStd_MapOfInteger& theShapeTypes, + const bool theIsAll ) +{ + myIsAll = theIsAll; + myShapeTypes = theShapeTypes; + myTypeFilter = new SALOME_TypeFilter( "GEOM" ); +} + +//======================================================================= +// function : IsOk +// purpose : +//======================================================================= +Standard_Boolean GEOM_ShapeTypeFilter::IsOk( + const Handle(SALOME_InteractiveObject)& anObj ) const +{ + if ( !myTypeFilter->IsOk(anObj) ) + return Standard_False; + + Standard_Boolean aResult = Standard_False; + GEOM::GEOM_Object_ptr aGeomObj = convertIOinGEOMObject( anObj, aResult ); + if ( !CORBA::is_nil( aGeomObj ) && aResult && aGeomObj->IsShape() ) + { + if ( myIsAll ) + return true; + TopoDS_Shape aShape; + if ( getShape( aGeomObj, aShape ) ) + { + if ( myShapeTypes.Contains( aShape.ShapeType() ) ) + return IsShapeOk( aShape ); + } + } + return Standard_False; } + +//======================================================================= +// function : IsShapeOk +// purpose : +//======================================================================= +Standard_Boolean GEOM_ShapeTypeFilter::IsShapeOk( const TopoDS_Shape& ) const +{ + return Standard_True; +} + + + + + + + + + + + + + + + + + + + + + + + +