Salome HOME
IPAL13617 NbSubMesh() method works wrong
[modules/smesh.git] / src / SMESH_I / SMESH_Mesh_i.cxx
index 164b27407e5de45f978b8c9f6374c491841cf9ae..6f0849f54d23ede204399e7dd62a8600db5cfd39 100644 (file)
@@ -522,41 +522,40 @@ SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aS
  */
 //=============================================================================
 
-SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
-                                 SMESH::SMESH_Hypothesis_ptr anHyp)
+SMESH_Hypothesis::Hypothesis_Status
+SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr       aSubShapeObject,
+                               SMESH::SMESH_Hypothesis_ptr anHyp)
 {
-        if(MYDEBUG) MESSAGE("removeHypothesis()");
-        // **** proposer liste de subShape (selection multiple)
+  if(MYDEBUG) MESSAGE("removeHypothesis()");
+  // **** proposer liste de subShape (selection multiple)
 
-        if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
-                THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
-                        SALOME::BAD_PARAM);
+  if (CORBA::is_nil(aSubShapeObject) && HasShapeToMesh())
+    THROW_SALOME_CORBA_EXCEPTION("bad subShape reference", SALOME::BAD_PARAM);
 
-        SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
-        if (CORBA::is_nil(myHyp))
-          THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
-                        SALOME::BAD_PARAM);
+  SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
+  if (CORBA::is_nil(myHyp))
+    THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference", SALOME::BAD_PARAM);
 
-        SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
-        try
-        {
-                TopoDS_Shape myLocSubShape;
-                //use PseudoShape in case if mesh has no shape
-                if(HasShapeToMesh())
-                  myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
-                else
-                  myLocSubShape = _impl->GetShapeToMesh();
-                
-                int hypId = myHyp->GetId();
-                status = _impl->RemoveHypothesis(myLocSubShape, hypId);
-                if ( !SMESH_Hypothesis::IsStatusFatal(status) )
-                  _mapHypo.erase( hypId );
-        }
-        catch(SALOME_Exception & S_ex)
-        {
-                THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
-        }
-        return status;
+  SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
+  try
+  {
+    TopoDS_Shape myLocSubShape;
+    //use PseudoShape in case if mesh has no shape
+    if(HasShapeToMesh())
+      myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
+    else
+      myLocSubShape = _impl->GetShapeToMesh();
+
+    int hypId = myHyp->GetId();
+    status = _impl->RemoveHypothesis(myLocSubShape, hypId);
+//     if ( !SMESH_Hypothesis::IsStatusFatal(status) ) EAP: hyp can be used on many subshapes
+//       _mapHypo.erase( hypId );
+  }
+  catch(SALOME_Exception & S_ex)
+  {
+    THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
+  }
+  return status;
 }
 
 //=============================================================================
@@ -572,8 +571,7 @@ throw(SALOME::SALOME_Exception)
   Unexpect aCatch(SALOME_SalomeException);
   if (MYDEBUG) MESSAGE("GetHypothesisList");
   if (_impl->HasShapeToMesh() && CORBA::is_nil(aSubShapeObject))
-    THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
-                                 SALOME::BAD_PARAM);
+    THROW_SALOME_CORBA_EXCEPTION("bad subShape reference", SALOME::BAD_PARAM);
 
   SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
 
@@ -669,6 +667,9 @@ void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
       if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
         aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
 
+//       if ( aSubShapeObject->_is_nil() ) // not published shape (IPAL13617)
+//         aSubShapeObject = theSubMesh->GetSubShape();
+
       aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
 
       // Update Python script
@@ -1976,20 +1977,37 @@ void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
                                   GEOM::GEOM_Object_ptr    theSubShapeObject )
 {
   MESSAGE("SMESH_Mesh_i::removeSubMesh()");
-  if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
+  if ( theSubMesh->_is_nil() /*|| theSubShapeObject->_is_nil()*/ )
     return;
 
-  try {
-    SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
-    for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
-      removeHypothesis( theSubShapeObject, aHypList[i] );
+  if ( theSubShapeObject->_is_nil() )  // not published shape (IPAL13617)
+  {
+    CORBA::Long shapeId = theSubMesh->GetId();
+    if ( _mapSubMesh.find( shapeId ) != _mapSubMesh.end())
+    {
+      TopoDS_Shape S = _mapSubMesh[ shapeId ]->GetSubShape();
+      if ( !S.IsNull() )
+      {
+        list<const SMESHDS_Hypothesis*> hyps = _impl->GetHypothesisList( S );
+        list<const SMESHDS_Hypothesis*>::const_iterator hyp = hyps.begin();
+        for ( ; hyp != hyps.end(); ++hyp )
+          _impl->RemoveHypothesis(S, (*hyp)->GetID());
+      }
     }
   }
-  catch( const SALOME::SALOME_Exception& ) {
-    INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
+  else
+  {
+    try {
+      SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
+      for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
+        removeHypothesis( theSubShapeObject, aHypList[i] );
+      }
+    }
+    catch( const SALOME::SALOME_Exception& ) {
+      INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
+    }
+    removeGeomGroupData( theSubShapeObject );
   }
-  removeGeomGroupData( theSubShapeObject );
-
   int subMeshId = theSubMesh->GetId();
 
   _mapSubMesh.erase(subMeshId);