From dd5e16f1de21523572a77d7c8511479cf095ca0e Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 13 Jan 2006 09:50:40 +0000 Subject: [PATCH] PAL10953. Add GetGeometryByMeshElement() --- idl/SMESH_Gen.idl | 25 ++++++++------- src/SMESH_I/SMESH_Gen_i.cxx | 62 +++++++++++++++++++++++++++++++++++-- src/SMESH_I/SMESH_Gen_i.hxx | 5 +++ 3 files changed, 79 insertions(+), 13 deletions(-) diff --git a/idl/SMESH_Gen.idl b/idl/SMESH_Gen.idl index 8db1c2990..bc6edfb72 100644 --- a/idl/SMESH_Gen.idl +++ b/idl/SMESH_Gen.idl @@ -133,15 +133,14 @@ module SMESH * First, verify list of hypothesis associated with the subShape, * return NOK if hypothesis are not sufficient */ - boolean Compute( in SMESH_Mesh theMesh, + boolean Compute( in SMESH_Mesh theMesh, in GEOM::GEOM_Object theSubObject ) raises ( SALOME::SALOME_Exception ); /*! - * + * Return true if hypotheses are defined well */ - - boolean IsReadyToCompute( in SMESH_Mesh theMesh, + boolean IsReadyToCompute( in SMESH_Mesh theMesh, in GEOM::GEOM_Object theSubObject ) raises ( SALOME::SALOME_Exception ); @@ -149,7 +148,7 @@ module SMESH * Return errors of hypotheses definintion * algo_error_array is empty if everything is OK */ - algo_error_array GetAlgoState( in SMESH_Mesh theMesh, + algo_error_array GetAlgoState( in SMESH_Mesh theMesh, in GEOM::GEOM_Object theSubObject ) raises ( SALOME::SALOME_Exception ); @@ -157,15 +156,19 @@ module SMESH * */ long_array GetSubShapesId( in GEOM::GEOM_Object theMainObject, - in object_array theListOfSubObjects ) + in object_array theListOfSubObjects ) raises ( SALOME::SALOME_Exception ); - + /*! - * + * Return geometrical object the given element is built on. + * The returned geometrical object, if not nil, is either found in the + * study or is published by this method with the given name */ - // long_array GetSubMeshesState( in object_array theListOfSubShape ) - // raises ( SALOME::SALOME_Exception ); - + GEOM::GEOM_Object GetGeometryByMeshElement( in SMESH_Mesh theMesh, + in long theElementID, + in string theGeomName) + raises ( SALOME::SALOME_Exception ); + }; }; diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index 6b07cada0..39c1b7629 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -69,6 +69,7 @@ #include "SMESH_Mesh.hxx" #include "SMESH_Hypothesis.hxx" #include "SMESH_Group.hxx" +#include "SMESH_MeshEditor.hxx" #include "SMDS_EdgePosition.hxx" #include "SMDS_FacePosition.hxx" @@ -1012,6 +1013,63 @@ CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh, return false; } +//================================================================================ +/*! + * \brief Return geometrical object the given element is built on + * \param theMesh - the mesh the element is in + * \param theElementID - the element ID + * \param theGeomName - the name of the result geom object if it is not yet published + * \retval GEOM::GEOM_Object_ptr - the found or just published geom object + */ +//================================================================================ + +GEOM::GEOM_Object_ptr +SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh, + CORBA::Long theElementID, + const char* theGeomName) + throw ( SALOME::SALOME_Exception ) +{ + Unexpect aCatch(SALOME_SalomeException); + if ( CORBA::is_nil( theMesh ) ) + THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM ); + + GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh(); + GEOM::GEOM_Gen_var geomGen = GetGeomEngine(); + + // get a core mesh DS + SMESH_Mesh_i* meshServant = SMESH::DownCast( theMesh ); + if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() ) + { + ::SMESH_Mesh & mesh = meshServant->GetImpl(); + SMESHDS_Mesh* meshDS = mesh.GetMeshDS(); + // find the element in mesh + if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) ) + // find a shape id by the element + if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) { + // get a geom object by the shape id + GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID )); + if ( geom->_is_nil() ) { + GEOM::GEOM_IShapesOperations_var op = + geomGen->GetIShapesOperations( GetCurrentStudyID() ); + if ( !op->_is_nil() ) + geom = op->GetSubShape( mainShape, shapeID ); + } + if ( !geom->_is_nil() ) { + // try to find the corresponding SObject + GeomObjectToShape( geom ); // geom client remembers the found shape + SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() ); + if ( SObj->_is_nil() ) + // publish a new subshape + SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape ); + // return only published geometry + if ( !SObj->_is_nil() ) + return geom._retn(); + } + } + } + return GEOM::GEOM_Object::_nil(); +} + //============================================================================= /*! * SMESH_Gen_i::Save @@ -1020,8 +1078,8 @@ CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh, */ //============================================================================= SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, - const char* theURL, - bool isMultiFile ) + const char* theURL, + bool isMultiFile ) { INFOS( "SMESH_Gen_i::Save" ); diff --git a/src/SMESH_I/SMESH_Gen_i.hxx b/src/SMESH_I/SMESH_Gen_i.hxx index 63bf5168b..f1cce1453 100644 --- a/src/SMESH_I/SMESH_Gen_i.hxx +++ b/src/SMESH_I/SMESH_Gen_i.hxx @@ -220,6 +220,11 @@ public: const SMESH::object_array& theListOfSubShape ) throw ( SALOME::SALOME_Exception ); + // Return geometrical object the given element is built on + GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh, + CORBA::Long theElementID, + const char* theGeomName) + throw ( SALOME::SALOME_Exception ); // **************************************************** // Interface inherited methods (from SALOMEDS::Driver)