Salome HOME
[bos #20282] EDF 22320 - general compute fails
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i_1.cxx
index 580663d464707729b7e045d832c8e7ee0444fd2f..a667ba59fcb13a21528c624c0b2f42204b09992e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -196,10 +196,15 @@ bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR)
 SALOMEDS::SObject_ptr SMESH_Gen_i::ObjectToSObject(CORBA::Object_ptr theObject)
 {
   SALOMEDS::SObject_wrap aSO;
-  if ( !CORBA::is_nil( theObject ))
+  try {
+    if ( !CORBA::is_nil( theObject ))
+    {
+      CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject );
+      aSO = getStudyServant()->FindObjectIOR( objStr.in() );
+    }
+  }
+  catch (...)
   {
-    CORBA::String_var objStr = SMESH_Gen_i::GetORB()->object_to_string( theObject );
-    aSO = getStudyServant()->FindObjectIOR( objStr.in() );
   }
   return aSO._retn();
 }
@@ -231,8 +236,8 @@ template<typename T> static inline T* objectToServant( CORBA::Object_ptr theIOR
 GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theShape )
 {
   GEOM::GEOM_Object_var aShapeObj;
-  if ( !theShape.IsNull() ) {
-    GEOM_Client* aClient = GetShapeReader();
+  if ( !theShape.IsNull() && mySMESHGen ) {
+    GEOM_Client* aClient = mySMESHGen->GetShapeReader();
     TCollection_AsciiString IOR;
     if ( aClient && aClient->Find( theShape, IOR ))
     {
@@ -252,9 +257,9 @@ GEOM::GEOM_Object_ptr SMESH_Gen_i::ShapeToGeomObject (const TopoDS_Shape& theSha
 TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
 {
   TopoDS_Shape S;
-  if ( !theGeomObject->_is_nil() && !theGeomObject->_non_existent() )
+  if ( mySMESHGen && !theGeomObject->_is_nil() && !theGeomObject->_non_existent() )
   {
-    GEOM_Client*           aClient = GetShapeReader();
+    GEOM_Client*           aClient = mySMESHGen->GetShapeReader();
     GEOM::GEOM_Gen_var aGeomEngine = GetGeomEngine( theGeomObject );
     if ( aClient && !aGeomEngine->_is_nil () )
       S = aClient->GetShape( aGeomEngine, theGeomObject );
@@ -262,6 +267,25 @@ TopoDS_Shape SMESH_Gen_i::GeomObjectToShape(GEOM::GEOM_Object_ptr theGeomObject)
   return S;
 }
 
+//================================================================================
+/*!
+ * \brief Get GEOM Object by its study entry
+ */
+//================================================================================
+
+GEOM::GEOM_Object_ptr SMESH_Gen_i::GetGeomObjectByEntry( const std::string& entry )
+{
+  GEOM::GEOM_Object_var go;
+  if ( !entry.empty() && mySMESHGen )
+  {
+    SALOMEDS::SObject_wrap so = mySMESHGen->getStudyServant()->FindObjectID( entry.c_str() );
+    CORBA::Object_var     obj = SObjectToObject( so );
+    go = GEOM::GEOM_Object::_narrow( obj );
+  }
+  return go._retn();
+}
+
+
 //=======================================================================
 //function : publish
 //purpose  :
@@ -985,8 +1009,23 @@ void SMESH_Gen_i::UpdateIcons( SMESH::SMESH_Mesh_ptr theMesh )
         {
           SMESH::array_of_ElementType_var elemTypes = idSrc->GetTypes();
           isEmpty = ( elemTypes->length() == 0 );
+
+          if ( !isEmpty )
+          {
+            // check if all sub-shapes of sub-mesh on group are computed
+            // (pb: "Compute sub-mesh" menu is missing if a sub-mesh is partially computed)
+            SMESH::SMESH_subMesh_var subMesh = SMESH::SMESH_subMesh::_narrow( obj );
+            if ( !subMesh->_is_nil() )
+              if ( SMESH_subMesh* sm = mesh_i->GetImpl().GetSubMeshContaining( subMesh->GetId() ))
+                if ( sm->IsComputedPartially() )
+                {
+                  SetPixMap( so, "ICON_SMESH_TREE_MESH_PARTIAL" );
+                  continue;
+                }
+          }
         }
       }
+
       if ( isEmpty )
         SetPixMap( so, "ICON_SMESH_TREE_MESH_WARN");
       else if ( !isGroup )
@@ -995,8 +1034,9 @@ void SMESH_Gen_i::UpdateIcons( SMESH::SMESH_Mesh_ptr theMesh )
         SetPixMap( so, "ICON_SMESH_TREE_GROUP_ON_FILTER" );
       else
         SetPixMap( so, "ICON_SMESH_TREE_GROUP" );
-    }
-  }
+
+    } // loop on sub-meshes or groups
+  } // loop on roots
 }
 
 //=======================================================================