Salome HOME
PAL10953. Add GetGeometryByMeshElement()
authoreap <eap@opencascade.com>
Fri, 13 Jan 2006 09:50:40 +0000 (09:50 +0000)
committereap <eap@opencascade.com>
Fri, 13 Jan 2006 09:50:40 +0000 (09:50 +0000)
idl/SMESH_Gen.idl
src/SMESH_I/SMESH_Gen_i.cxx
src/SMESH_I/SMESH_Gen_i.hxx

index 8db1c299099d430ff1a8e76061678149abc58fbc..bc6edfb72418dbf02fc75f4913085d9f6b087f13 100644 (file)
@@ -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 );
+
   };
 
 };
index 6b07cada0dd712b663611b3cd92334778aba4b51..39c1b762968c21302889cff1d72a09c660ec8f76 100644 (file)
@@ -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<SMESH_Mesh_i*>( 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" );
 
index 63bf5168b14c0371ce43c327014d0db651231935..f1cce14532e39807622b9cc37fa4ab113f6b83e6 100644 (file)
@@ -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)